ViperSBT Posted June 13, 2008 Share Posted June 13, 2008 OK, I need to figure out how many people attended my events on different weekends.... For the people I have a table: Table: attendance Fields: id person event For the events table: Table: events Fields: id name date I can handle doing a query like: SELECT a.person, e.name, e.date FROM attendance a JOIN events e ON a.event = e.id So, that gives me a history of all the people and the event and date they have attended. What I am looking for is a history of all the people that have attended multiple events on dates that are greater than 4 days apart from each other. Can this be done in a query? Quote Link to comment Share on other sites More sharing options...
Barand Posted June 13, 2008 Share Posted June 13, 2008 yes. SELECT a.person, e.name, e.date FROM a_attendance a INNER JOIN a_events e ON a.event=e.id WHERE a.person IN (SELECT a.person FROM a_attendance a INNER JOIN a_events e ON a.event=e.id GROUP BY a.person HAVING DATEDIFF(MAX(date),MIN(e.date)) > 4) ORDER BY a.person, e.date Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.