0
這裏的月產量報告我的表PROD:總和同一列不同的方式
PruID Prod1 Prod2, ReportDate
001 12.5 32.4 1/1/1999
001 13.0 32.0 2/1/1999
...
002 45.2 32.4 1/1/2004
002 56.3 43.2 2/1/2004
...
我想總結PROD1和Prod2的,以及過去12個月PROD1 & Prod2的由PruID。我寫了2個獨立的查詢,他們正在針對各種用途:
查詢1:總結PROD1 & Prod2的由PruID
SELECT Prod.PruID, Sum(Prod.Prod1) AS CumProd1, Sum(Prod.Prod2) AS CumProd2
FROM Prod
GROUP BY Prod.PruID;
查詢2:總結過去12個月PROD1 &的Prod2的由PruID
SELECT PruID, Sum(Prod1) AS Cum12MonProd1, Sum(Prod2) AS Cum12MonProd2
FROM Prod
WHERE Prod.ReportDate > DATEADD('m', -12, now())
GROUP BY PruID;
如何將2個查詢結合一體,以生產這樣的事情:
PruID CumProd1 CumProd2 Cum12MonProd1 Cum12MonProd2