2015-06-19 29 views
0

我有一个查询,我从一列中创建2个值作为两个独立的列,每个列都有不同的值。我有这两个列的查询返回相同的值。 但我需要为每个值得到不同的值。第一个'劳动强度'返回'需求ID'的结果,并得到它的正确值。来自同一列的两个不同值作为单独列返回相同的结果

我已经在他们之前用*标记了这2列。

select 
document.id AS API_ID, 
document.name AS NAME, 
document.description AS DESCRIPTION, 
document.documentKey AS DOCUMENT_KEY, 
docs.sequence AS SEQUENCE, 
documentcustomfieldvalue.documentId AS DOCUMENT_ID, 
*MAX(CASE WHEN documenttypefielddefinition.label = 'Labor Intensity' THEN textValue ELSE NULL END) AS DARBIETILPIBA, 
*MAX(CASE WHEN documenttypefielddefinition.label = 'Requirements ID' THEN textValue ELSE NULL END) AS PRASIBAS_ID, 
from document 
join (select doc.id, doc.name, dn.sequence, dn.globalSortOrder 
     from document doc, documentnode dn 
     where doc.projectId = 20249 -- report_projectId 
     and dn.scopeId = 5 
     and dn.refId = doc.id 
     and dn.baseLineId is null 
     and dn.sequence like '2%') docs on docs.id = document.id 
join project on document.projectId= project.id 
left join documentcustomfieldvalue on documentcustomfieldvalue.documentId = document.id 

left join documenttype on document.documentTypeId = documenttype.id 
left join documenttypefielddefinition on documenttype.id = documenttypefielddefinition.documentTypeId 
left join documentfield on documenttypefielddefinition.documentFieldId = documentfield.id 
left join userbase on documentcustomfieldvalue.textValue = userbase.id 

where document.projectId = project.id 
and document.active = 'T' and documenttypefielddefinition.label IN ('Labor Intensity','Requirements ID') 
group by docs.sequence 
order by docs.globalSortOrder 

什么可能是错误,使该值作为重复?如果我在where语句中只留下'Labor Intensity',那么它仍然会给出'Labor Intensity'值的'Requirements ID'值。

如果你不明白的东西,请让我澄清一些事情。 谢谢!

回答

0

我想通了什么是错的。一个左连接错误,需要额外设置。

当前正在工作的左连接。

left join documenttype on document.documentTypeId = documenttype.id 
left join documenttypefielddefinition on documenttype.id = documenttypefielddefinition.documentTypeId 
left join documentfield on documenttypefielddefinition.documentFieldId = documentfield.id 
left join documentcustomfieldvalue on document.id = documentcustomfieldvalue.documentId 
and documentfield.id = documentcustomfieldvalue.fieldId 
left join userbase on documentcustomfieldvalue.textValue = userbase.id 
相关问题