Alias names to with rollup in SQL queries?

后端 未结 3 1198
别那么骄傲
别那么骄傲 2020-12-11 01:16

I am using with rollup in my sql query. I am not getting alias name for rollup.

My SQL is

SELECT [Column1],
       sum([Column2])
FROM           


        
相关标签:
3条回答
  • 2020-12-11 01:59
    select 
    isnull([column1],'rollup'), 
    sum([column2] )
    from tableA
    group by [column1] 
    WITH ROLLUP
    
    0 讨论(0)
  • 2020-12-11 02:08
    SELECT ifnull([column1],'total'),
           sum([Column2])
    FROM   Tablea
    GROUP  BY [Column2] WITH ROLLUP 
    
    0 讨论(0)
  • 2020-12-11 02:14

    You can use the GROUPING function in a CASE expression.

    SELECT CASE
             WHEN GROUPING([Column1]) = 1 THEN 'Total'
             ELSE [Column1]
           END [Column1],
           sum([Column2])
    FROM   Tablea
    GROUP  BY [Column1] WITH ROLLUP 
    

    SQL Fiddle

    0 讨论(0)
提交回复
热议问题