php - Query to see how many times employees has worked same shifts -
i run management system people work different shifts registered.
i'd able make display of how many times each worker/volunteer worked same shifts, this:
|amy|carl|max| |---|----|---| amy | x | 2 | 6 | carl| 2 | x | 5 | max | 6 | 5 | x | i hoping had ideas how form query. idea i've come far make php create custom query each user.
select count(common between user 1 , 2), count(common between user 1 , ...) select count(common between user 2 , 1), count(common between user 2 , ...) etc..
i consider ugly way , hoping there way of retrieving data within single query.
the database stored this:
shifts
- id
- from
- to
working
- id
- shiftid
- userid
users
- id
- name
you'll have self-join working table:
select a.userid, b.userid, count(a.shiftid) common_shifts working inner join working b on ((a.shiftid = b.shiftid) , (a.userid <> b.userid)) having common_shifts > 0
Comments
Post a Comment