我有这个查询
SELECT ProjInfo.ProjectN AS BS,
ProjShipp.Parts,
SUM(CASE
WHEN DailyPaProd.FK_idNextProcess = 13
AND ProjInfo.FK_Status != 'VENDRE DES MATIERES PREMIERES' THEN ProjShipp.[Weight] * DailyPaProd.[Quantity]
ELSE 0
END) AS [weight fab],
SUM(ProjShipp.[Weight] * ProjShipp.ShippingNavisionQty) AS [weight Shipp]
FROM ProjectShipping ProjShipp
INNER JOIN ProjectInfo ProjInfo ON ProjInfo.id = ProjShipp.IdProject
INNER JOIN DailyPaintProduction DailyPaProd ON DailyPaProd.FK_idPartShip = ProjShipp.id
WHERE ProjInfo.ProjectN = 'BS-00799'
GROUP BY ProjInfo.ProjectN,
ProjShipp.Parts,
ProjShipp.[Weight];
当我运行它时,我得到这个结果
所有结果都是正确的,除了重量Shipp列上的TA1我应该得到2352而不是11760。为什么我得到这个错误,以及如何解决它 预先感谢。
答案 0 :(得分:-1)
此查询对我有用
SELECT ProjInfo.ProjectN AS BS,
ProjShipp.Parts,
(Select SUM(ProjectShipping.[Weight]*DailyPaintProduction.[Quantity])
from DailyPaintProduction
Inner Join ProjectShipping on ProjectShipping.id=DailyPaintProduction.FK_idPartShip
Inner Join ProjectInfo on ProjectInfo.id=ProjectShipping.IdProject
Where DailyPaintProduction.FK_idPartShip=ProjShipp.id and
FK_idNextProcess=13 and
ProjectInfo.FK_Status!='VENDRE DES MATIERES PREMIERES')AS 'weight fab',
SUM(ProjShipp.[Weight]*ShippingNavisionQty)AS 'weight Shipp'
From ProjectShipping ProjShipp
Inner Join ProjectInfo ProjInfo on ProjInfo.id=ProjShipp.IdProject
WHERE ProjInfo.ProjectN = 'BS-00799'
GROUP BY ProjInfo.ProjectN,
ProjShipp.Parts,
ProjShipp.[Weight],
ProjShipp.id