Du skal bruge betinget aggregering for at summere de forskellige leave_hours
separat:
SELECT employee_id,
SUM(overtime_hours) AS ot,
SUM(CASE WHEN leave_type = 1 THEN leave_hours ELSE 0 END) AS leave_1,
SUM(CASE WHEN leave_type = 2 THEN leave_hours ELSE 0 END) AS leave_2
FROM `table`
GROUP BY employee_id
Output:
employee_id ot leave_1 leave_2
3 2.3 7.6 5
Bemærk, at hvis du bruger flydende decimaltal til at gemme timerne, skal du muligvis ROUND
resultaterne.