题解 | 统计加班员工占比
with temp as ( select department, count(a.staff_id) as cnt, count(if((unix_timestamp(last_clockin)-unix_timestamp(first_clockin))/3600>9.5,1,null)) as ban_cnt from staff_tb a join attendent_tb b on a.staff_id=b.staff_id group by department) select department, concat(round((ban_cnt/cnt)*100,1),'%') as ratio from temp order by ratio desc