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;
版权属于:青阳のBlog
本文链接:https://www.hipyt.cn/325.html
作品采用:《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
转载时须注明出处及本声明
此处评论已关闭