Jump to content

Cross table query help needed


ViperSBT

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.