新建表:
TEST_TEACHER(id,name,dw_name,sex,degree)。
使用ratio_to_report() over()实现求出比例:
select DW_NAME, COUNT(DW_NAME) as SUM,
ratio_to_report(COUNT(1)) OVER(),
COUNT(CASE WHEN SEX='男' THEN 1 END) as Man, COUNT(CASE WHEN SEX='女' THEN 1 END) as Women
from TEST_TEACHER
group by DW_NAME order by DW_NAME;
输出结果如下图所示:其中计算机3个老师,总数10个老师,比例占0.3。