Oracle 数据库 SQL 语句
- 1、分组之后再合计
- 2、显示不为空的值
1、分组之后再合计
关键字: grouping sets ((分组字段1,分组字段2),())
select sylbdm ,count(sylbmc) as rs,round(count(sylbmc)/(select count(sylbmc) from bmk),4)*100 || '%' as bl
from bmk
GROUP BY grouping sets ((sylbdm ),())
2、显示不为空的值
关键字: coalesce合并多个字段,显示第一个不为null的值
select COALESCE(sylbdm, '合计') as lx,count(sylbdm) as rs,ROUND(COUNT(sylbdm) / (select count(*) from BMK) * 100, 2) || '%' AS blfrom BMKgroup by GROUPING SETS ((sylbdm), ())