繁体   English   中英

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

[英]Two different values from same column as seperate columns return same results

我有一个查询,其中我从一列中得出2个值,作为两个单独的列,每个列都有不同的值。 我的查询为这两列返回相同的值。 但是我需要为每个获取不同的值。 第一个“劳动强度”返回“需求ID”的结果,并且得到正确的值。

我在这两列之前用*标记。

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