Add a summary row with totals

后端 未结 5 1660
不知归路
不知归路 2020-11-27 02:55

I know this sounds crazy and probably should not be done this way but I need something like this - I have a records from SELECT [Type], [Total Sales] From Before

5条回答
  •  臣服心动
    2020-11-27 03:30

    You could use the ROLLUP operator

    SELECT  CASE 
                WHEN (GROUPING([Type]) = 1) THEN 'Total'
                ELSE [Type] END AS [TYPE]
            ,SUM([Total Sales]) as Total_Sales
    From    Before
    GROUP BY
            [Type] WITH ROLLUP
    

提交回复
热议问题