I have three tables, I want to query which people were absent (missing in the event i.e when a idu is missing in the attendance table for a certain event) from an event and how many times they were absent within a certain date range. For example if an event happens 5 times and a user goes to one of them, I want to be shown that a user missed Four events. I also would like to set the least amount of times an individual can be absent to be included in the absentee list to be 3. Therefore the query will show me users who have missed events more than 3 time. My tables are as show below
Users Table
idu fname lname 1 John Doe 2 Jane Doe 3 Mary Jane 4 John Rancho Events Table
id_event event_name 1 Conference 2 Fellowship 3 Orientation Events attendance table
id_attendance id_event idu event_date 1 1 1 2012-02-01 08:00:00 2 1 2 2012-02-01 08:00:00 3 2 1 2012-06-07 08:00:00 4 2 3 2012-06-07 08:00:00 5 3 1 2013-07-12 08:00:00 6 3 2 2013-07-12 08:00:00 7 1 1 2014-05-31 08:00:00 8 1 3 2014-05-31 08:00:00 9 2 1 2015-02-08 08:00:00 I would like the results to be shown as below whereby the first column is the idu Therefore the results will look like so
IDU Name Times Absent 2 Jane Doe 3 3 Mary Jane 4 My query is shown below. I'm stuck.
SELECT idu FROM users WHERE idu NOT IN ( SELECT idu FROM events LEFT JOIN attendance ON event_id=id_event WHERE event_date>='2011-04-08 00:00:00' AND event_date<='2019-04-08 00:00:00' AND id_event IN(11,10) AND idu IS NOT NULL) 