以下是列表数据.
Code ItemCount Type Amount ---------------------------------------- B001 1 Dell 10.00 B001 1 Dell 10.00 B001 1 Apple 10.00 B001 2 Apple 20.00 B001 2 Apple 20.00 B114 1 Apple 30.50 B114 1 Apple 10.00
我需要一个结果,按代码和类型进行分组,并且总计ItemCount,并获得每行中的Amount的总计.
这可能吗?
Code ItemCount Type Amount ---------------------------------------- B001 2 Dell 110.50 B001 5 Apple 110.50 B114 2 Apple 110.50
解决方法
请尝试:
SELECT Code,SUM(ItemCount) ItemCount,Type,(SELECT SUM(Amount) FROM YourTable) Amount FROM YourTable GROUP BY Code,Type