Add a summary row with totals

后端 未结 5 1664
不知归路
不知归路 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条回答
  •  猫巷女王i
    2020-11-27 03:44

    Try to use union all as below

    SELECT [Type], [Total Sales] From Before
    union all
    SELECT 'Total', Sum([Total Sales]) From Before
    

    if you have problem with ordering, as i-one suggested try this:

    select [Type], [Total Sales] 
    from (SELECT [Type], [Total Sales], 0 [Key] 
          From Before 
          union all 
          SELECT 'Total', Sum([Total Sales]), 1 From Before) sq 
    order by [Key], Type
    

提交回复
热议问题