AS别名不能直接是数字,相当于以字符形式展示,
示例sql
select
(case name when name then name ELSE '合计' END ) AS 用户,
count(case HOUR(recordTime) when '0' then '0' END ) AS '00' ,
count(case HOUR(recordTime) when '1' then '1' END ) AS '01' ,
count(case HOUR(recordTime) when '2' then '2' END ) AS '02' ,
count(case HOUR(recordTime) when '3' then '3' END ) AS '03' ,
count(case HOUR(recordTime) when '4' then '4' END ) AS '04' ,
count(case HOUR(recordTime) when '5' then '5' END ) AS '05' ,
count(case HOUR(recordTime) when '6' then '6' END ) AS '06' ,
count(case HOUR(recordTime) when '7' then '7' END ) AS '07' ,
count(case HOUR(recordTime) when '8' then '8' END ) AS '08' ,
count(case HOUR(recordTime) when '9' then '9' END ) AS '09' ,
count(case HOUR(recordTime) when '10' then '10' END ) AS '10' ,
count(case HOUR(recordTime) when '11' then '11' END ) AS '11' ,
count(case HOUR(recordTime) when '12' then '12' END ) AS '12' ,
count(case HOUR(recordTime) when '13' then '13' END ) AS '13' ,
count(case HOUR(recordTime) when '14' then '14' END ) AS '14' ,
count(case HOUR(recordTime) when '15' then '15' END ) AS '15' ,
count(case HOUR(recordTime) when '16' then '16' END ) AS '16' ,
count(case HOUR(recordTime) when '17' then '17' END ) AS '17' ,
count(case HOUR(recordTime) when '18' then '18' END ) AS '18' ,
count(case HOUR(recordTime) when '19' then '19' END ) AS '19' ,
count(case HOUR(recordTime) when '20' then '20' END ) AS '20' ,
count(case HOUR(recordTime) when '21' then '21' END ) AS '21' ,
count(case HOUR(recordTime) when '22' then '22' END ) AS '22' ,
count(case HOUR(recordTime) when '23' then '23' END ) AS '23' ,
count(name) AS 总计
from tt_record
where 1=1
and recordTime>= '2021-04-14 00:00:00'
and recordTime<= '2021-04-14 23:59:59'
group by name
WITH ROLLUP;