我有一个查询,我希望按年度计算所有供应商的购买量。但是,我的结果并没有像我想要的那样由供应商汇总。我相信这是因为我必须把IJDATE放在GROUP BY中。有什么建议我可以解决这个问题吗?
SELECT
YEAR(ij.IJDATE) AS YearPurchased,
ISNULL(SUM(ij.IJCOST * ij.IJQTY), 0) AS YearlySpend,
IJVEND AS Vendor
FROM
dbo.S2K_IJ ij
WHERE
ij.IJTYPE IN ('I', 'ID')
GROUP BY
ij.IJDATE,
ij.IJVEND
ORDER BY
YearPurchased,
Vendor
答案 0 :(得分:1)
尝试将您的分组更改为:
GROUP BY
YEAR(ij.IJDATE),
ij.IJVEND