简体   繁体   English

同一列中的两个不同值作为单独的列返回相同的结果

[英]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. 我有一个查询,其中我从一列中得出2个值,作为两个单独的列,每个列都有不同的值。 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. 第一个“劳动强度”返回“需求ID”的结果,并且得到正确的值。

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. 如果我在where语句中仅保留“劳动强度”,那么它仍然为我提供“劳动强度”值的“需求ID”值。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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