青阳Blog-云计算与技术探索 | 原创文章与建站教程 | 群晖NAS教程

with rollup用法

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

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

2.用了with rollup:

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

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;

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »