with rollup用法

2022-10-09T16:48:59

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;

当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »