I have the following query:
SELECT num_hours, rate, st.tech_code
FROM ost_hours ht
LEFT JOIN ost_staff st ON ht.tech_code = st.tech_code
LIMIT 0 , 30
which results in the following:
num_hours rate tech_code
20 overtime_rate 2
4 overtime_rate 1
10 normal_rate 1
1 overtime_rate 4
1 overtime_rate 4
2 normal_rate 4
3 normal_rate 4
1.5 normal_rate 6
1.5 normal_rate 6
2 normal_rate 4
1 normal_rate 4
What I want it to result in is a sum per rate for each tech_code, so for example for tech codes 4 and 6 it would be the following:
total_hours rate tech_code
8 normal_rate 4
2 overtime_rate 4
3 normal_rate 6
I hope that’s clear, everything I’ve done has resulted in unexpected and inaccurate data. I assume I need something to do with group by but every time I try something the result is totally bizarre.
Edit: Changed confusing “count” to “sum”
1 Answer