简体   繁体   中英

Two different values from same column as seperate columns return same results

I have a query where I make 2 values from one column to be as two seperate columns which each has different values. The query I have returns the same values for both of these columns. But I need to get different values for each. The first one 'Labor Intensity' returns the results of the 'Requirements ID' and that one gets it's correct values.

I have marked those 2 columns with * before them.

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

What could be the error that makes that value as a duplicate? If I leave only 'Labor Intensity' in the where statement, then It still gives me the 'Requirements ID' values for the 'Labor Intensity' values.

If you can't understand something, please ask me to clarify that something. Thank you!

I figured out what was wrong. One left join was wrong and needed additional setting.

Current left joins that is working.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM