Add a summary row with totals

后端 未结 5 1673
不知归路
不知归路 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

    If you want to display more column values without an aggregation function use GROUPING SETS instead of ROLLUP:

    SELECT
      Type = ISNULL(Type, 'Total'),
      SomeIntColumn = ISNULL(SomeIntColumn, 0),
      TotalSales = SUM(TotalSales)
    FROM atable
    GROUP BY GROUPING SETS ((Type, SomeIntColumn ), ())
    ORDER BY SomeIntColumn --Displays summary row as the first row in query result
    

提交回复
热议问题