I’ve been chasing my tail on this one. I have a single table (keeping it simple for this example).
LogID (Primary Key)
UserID (Foreign Key)
Skipped (Tiny Int, default 0) can be 1 or 0
This is a one to many relation, this table being the ‘many’ in this join
A user ie: John Smith might have a UserID of 10. Each record can have a skipped = 1 or Skipped = 0 depending on the instance for the particular record.
Here is a simple break down of data
1 | 10 | 1
2 | 10 | 0
3 | 10 | 1
4 | 10 | 0
So this user is in there 4 times. 2 records show skipped (1) and 2 records show not skipped (0).
I need to create a query to find users that are 100% skipped. So a person who looks like this:
1 | 11 | 1
2 | 11 | 1
3 | 11 | 1
4 | 11 | 1
If Skipped is 0 I don’t want that user. Users can be mixed (skipped yes and no), so I need to find a user that is 100% skipped only. I will need it GROUPed by UserID or at least DISTINCT handling on it when found, so I get single users (no dups). I’ve been spinning my head around on GROUP BYs, HAVINGS, COUNTs and SUMs to get this, but I keep getting caught up on the 100% portion of the query.
I’m using MySQL 5.1.56
Any suggestions are greatly appreciated.
Thanks!
hanji
1 Answer