在我的代碼,我需要得到關於某些部件編號的數據,我遇到了一個奇怪的問題,當我運行代碼:能增加更多的左外連接影響以前的列
SELECT
tblensembleunepiece.ENSPIECEID,
tblensembleunepiece.NOPIECE As 'Part Number',
tblensembleunepiece.DESCRIPTIONENSP As 'Description',
tblensembleunepiece.QTEMIN As 'Min',
tblensembleunepiece.QTEMAX As 'Max',
tbltypepiece.TITRETYPE,
case
when CONSOMMABLE='true' Then 'Consumeable'
else 'Rotable' end As 'Utilization',
sum(tblitem.NBPOURPACK) As 'Serviceable',
sum(case when tblquarantaine.BER = 'false' Then 1 else 0 END) As 'Quarantine Repairable',
sum(case when tblquarantaine.BER = 'true' Then 1 else 0 end) As 'Quarantine BER/Scrap',
sum(case when tblbonsortieitem.VAREVENIR = 'true' Then 1 else 0 end) As 'Repair Line',
sum(case when (tblhistorique.REMARQUE LIKE "Added to operation cost%" OR tblhistorique.REMARQUE LIKE "Added to operational cost%")
then (substring_index(LTRIM(substring_index(tblhistorique.REMARQUE, 'Qty:', -1)), '.', 1)+0)
when (tblhistorique.REMARQUE LIKE "Removed from operation cost%" OR tblhistorique.REMARQUE LIKE "Removed from operational cost%")
then (substring_index(LTRIM(substring_index(tblhistorique.REMARQUE, 'Qty:', -1)), ' ', 1)*(-1)) else 0 end)
FROM
tblensembleunepiece
JOIN tbltypepiece ON tblensembleunepiece.TYPEPIECEID = tbltypepiece.TYPEPIECEID
JOIN tblitem ON tblensembleunepiece.ENSPIECEID = tblitem.ENSPIECEID
LEFT OUTER JOIN tblquarantaine ON tblquarantaine.ITEMID = tblitem.ITEMID
LEFT OUTER JOIN tblbonsortieitem ON tblbonsortieitem.ITEMID = tblitem.ITEMID
LEFT OUTER JOIN tblhistorique ON tblhistorique.ITEMID = tblitem.ITEMID
WHERE
tblensembleunepiece.NOPIECE<>''
GROUP BY tblensembleunepiece.ENSPIECEID;
然後我得到的錯誤數據。雖然,在SELECT子句中添加最後一個sum語句並在FROM子句中添加最後一個LEFT OUTER JOIN之前,一切正常。
Serviceable列是在添加額外代碼時發生錯誤的列,它輸出的值比它們應該大4倍(不是所有值,但大多數)。
添加更多左外連接可能會導致以前的列更改嗎?
爲什麼要添加一個不影響所選內容的連接?這將是有點毫無意義... –
我不能使用子查詢數據庫不支持它 – JahKnows