在我的代码中,我需要获取有关某些零件号的数据,当我运行代码时遇到了一个奇怪的问题:
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 倍(不是所有值,而是大多数值)。
添加更多的左外连接是否有可能导致前面的列发生变化?