SELECT DISTINCT [SC Vermorel SRL$Production Order].No_,
[SC Vermorel SRL$Production Order].[Replan Ref_ No_],
[SC Vermorel SRL$Production Order].Description,
[SC Vermorel SRL$Production Order].[Source No_],
[SC Vermorel SRL$Production Order].[Routing No_],
[SC Vermorel SRL$Production Order].Quantity,
[SC Vermorel SRL$Production Order].[Old Prod_ Order No_],
[SC Vermorel SRL$Routing Line].[Run Time],
[SC Vermorel SRL$Routing Line].[Run Time] * [SC Vermorel SRL$Production Order].Quantity AS TotalOre,
[SC Vermorel SRL$Prod_ Order Line].[Finished Quantity],
SUM([SC Vermorel SRL$ProductieZilnica].[Cantitate sudura]) AS [Cantitate sudura],
SUM([SC Vermorel SRL$ProductieZilnica].[Cantitate montaj]) AS [Cantitate montaj]
FROM [SC Vermorel SRL$Production Order]
INNER JOIN [SC Vermorel SRL$Routing Line]
ON [SC Vermorel SRL$Production Order].[Routing No_] = [SC Vermorel SRL$Routing Line].[Routing No_]
INNER JOIN [SC Vermorel SRL$Prod_ Order Line]
ON [SC Vermorel SRL$Production Order].No_ = [SC Vermorel SRL$Prod_ Order Line].[Prod_ Order No_]
INNER JOIN [SC Vermorel SRL$ProductieZilnica]
ON [SC Vermorel SRL$Production Order].No_ = [SC Vermorel SRL$ProductieZilnica].RPO
WHERE ([SC Vermorel SRL$Production Order].Status = 3)
AND ([SC Vermorel SRL$Production Order].[Location Code] = 'MACH FIN')
AND ([SC Vermorel SRL$Production Order].[Gen_ Prod_ Posting Group] = 'FINISHED G')
AND ([SC Vermorel SRL$Routing Line].No_ = '150')
GROUP BY [SC Vermorel SRL$Production Order].No_
我需要的所有條目的總和,從另一個表([SC Vermorel SRL$ProductieZilnica]
)從[SC Vermorel SRL$Production Order]
表對應於每個不同No_
重視。SELECT DISTINCT總和 - GROUP BY
我不相信上帝的愛使它工作。有人能指引我朝着正確的方向嗎?
的SQL Server 2005。 2015. –
你有沒有使用AS關鍵字來簡化你的名字? – Steve
截然不同,在同一個查詢中group by是毫無意義的,這個group將會使它不同。在你的組中,你必須編寫你選擇的每一列(除了函數,如max,min,sum,...)你的查詢不會這樣做,因此它不會工作,但會返回錯誤。 – GuidoG