簡體   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