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? Link to comment https://forums.phpfreaks.com/topic/110135-cross-table-query-help-needed/ 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 Link to comment https://forums.phpfreaks.com/topic/110135-cross-table-query-help-needed/#findComment-565279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.