Group by two columns and display grand total in every row

后端 未结 6 1075
太阳男子
太阳男子 2020-12-06 05:00

Below are the list data.

Code   ItemCount   Type      Amount 
----------------------------------------
B001    1          Dell         10.00
B001    1                


        
6条回答
  •  忘掉有多难
    2020-12-06 05:21

    The amounts you give differ from the sample data but this works for the sample data values:

    SELECT Code, SUM(ItemCount) AS ItemCount, [Type], SUM(Amount) AS Amount 
    FROM dbo.TestSubs GROUP BY Code,[Type] ORDER BY Code
    

提交回复
热议问题