with rollup用法:
1.没用with rollup:

SELECT name, SUM(signin) as signin_count 
 FROM  employee_tbl 
 GROUP BY name

1665305245950.png

2.用了with rollup:

SELECT name, SUM(signin) as signin_count 
 FROM  employee_tbl 
 GROUP BY name 
 WITH ROLLUP;

1665305267666.png

3.如果用了with rollup,想把“NULL”改成其他名字,可用coalesce:

参数说明:如果a为null,则选择b;如果b==null,则选择c;如果a!=null,则选择a;如果a b c 都为null ,则返回为null(没意义)。

SELECT coalesce(name, '总数'), SUM(signin) as signin_count 
FROM  employee_tbl 
GROUP BY name 
WITH ROLLUP;

1665305283173.png

最后修改:2022 年 10 月 09 日
如果觉得我的文章对你有用,请随意赞赏