select department,concat(round(sum(if(sumtime > 9.5,1,0))/count(*)*100,1),"%") ratio from ( select staff_id,timestampdiff(minute,first_clockin,last_clockin)/60 sumtime from attendent_tb at) as t1 join staff_tb st on t1.staff_id = st.staff_id group by department order by ratio desc 笨方法