with a as ( select '部门' as type,dept as "部门",count(1) as num from "考勤表" where "考勤时间"<100 group by dept union all select '公司' as type,'公司' as "部门",count(1) as num from "考勤表" where "考勤时间"<100 ), b as ( select '部门' as type,dept as "部门",count(1) as num from "员工表" group by dept union all union all select '公司' as type,'公司' as "部门",count(1) as num from "员工表" ) select a.type,a."部门",a.num/b.num as rate from a left join b on a.type=b.type and a.部门=b.部门