题解 | 统计加班员工占比
SELECT
st.department,
CONCAT(ROUND(COUNT(ot.staff_id)/COUNT(st.staff_id)*100 , 1),'%') ratio
FROM(
SELECT staff_id
FROM attendent_tb
WHERE TIMESTAMPDIFF(MINUTE,first_clockin, last_clockin)/60 > 9.5
)ot
RIGHT JOIN staff_tb st ON ot.staff_id = st.staff_id
GROUP BY st.department
ORDER BY ratio DESC
查看3道真题和解析