I have a table of shifts which are entered into a rota application. Let's call them rotaItems. a section of the rotaItems table looks like something like this:
itemId personId weekId dayId hours
=============================================
1 1234 10 2 3
1 1234 10 2 6
1 1234 10 2 7
2 2222 10 2 9
3 5432 10 2 12
4 7890 10 2 9
I need to count how many personId's are working each day, which could be achieved by:
SELECT COUNT(*) FROM rotaItems WHERE weekId=10 AND dayId=2 GROUP BY personId
However....as you can see there might be more than one entry per person per day (if they say work a morning and evening shift). So for personId=1234, 3 would be returned but I only want 1, since it is a person count I want not a shift count. I'm going round in circles trying to work out how, but basically I think I want:
SELECT COUNT(*) ###UP TO MAX OF ONE PER dayId#### FROM rotaItems WHERE weekId=10 AND dayId=2 GROUP BY personId
Thanks in advance!
itemId personId weekId dayId hours
=============================================
1 1234 10 2 3
1 1234 10 2 6
1 1234 10 2 7
2 2222 10 2 9
3 5432 10 2 12
4 7890 10 2 9
I need to count how many personId's are working each day, which could be achieved by:
SELECT COUNT(*) FROM rotaItems WHERE weekId=10 AND dayId=2 GROUP BY personId
However....as you can see there might be more than one entry per person per day (if they say work a morning and evening shift). So for personId=1234, 3 would be returned but I only want 1, since it is a person count I want not a shift count. I'm going round in circles trying to work out how, but basically I think I want:
SELECT COUNT(*) ###UP TO MAX OF ONE PER dayId#### FROM rotaItems WHERE weekId=10 AND dayId=2 GROUP BY personId
Thanks in advance!