方法一:ifnull()
with base_tb1 as( select s.department,count(*) as total from staff_tb s inner join attendent_tb a on s.staff_id = a.staff_id group by department), base_tb2 as ( select s.department,case when count(*) =null then 0 else count(*) end as fenzi from staff_tb s inner join attendent_tb a on s.staff_id = a.staff_id where round(timestampdiff(minute,a.first_clockin,last_clockin)/60,1)>9.5 group by department ) select b1.department, concat(round(ifnull(b2.fenzi,0)/b1.total*100,1),'%') as ratio from base_tb1 b1 left join base_tb2 b2 on b1.department = b2.department