human
Schema:
Services (Service_ID, Service_Type_Code)
Participants (Participant_ID, Participant_Type_Code, Participant_Details)
Events (Event_ID, Service_ID, Event_Details)
Participants_in_Events (Event_ID, Participant_ID)
Please answer with SQL.
assistant
Sure, I understand.
human
What are all the the participant ids, type code and details?
assistant
SELECT Participant_ID , Participant_Type_Code , Participant_Details FROM Participants
human
How many events did not have any participants?
assistant
SELECT count(*) FROM EVENTS WHERE event_id NOT IN (SELECT event_id FROM Participants_in_Events)
human
How many events have each participants attended? List the participant id, type and the number.
assistant
SELECT T1.Participant_ID , T1.Participant_Type_Code , count(*) FROM Participants AS T1 JOIN Participants_in_Events AS T2 ON T1.Participant_ID = T2.Participant_ID GROUP BY T1.Participant_ID
human
What is the id of the event with the most participants?
assistant
SELECT Event_ID FROM Participants_in_Events GROUP BY Event_ID ORDER BY count(*) DESC LIMIT 1
human
What are the ids and details of events that have more than one participants?
assistant
SELECT T1.event_id , T1.event_details FROM EVENTS AS T1 JOIN Participants_in_Events AS T2 ON T1.Event_ID = T2.Event_ID GROUP BY T1.Event_ID HAVING count(*) > 1
human
What are all the distinct participant ids who attended any events?
assistant
SELECT COUNT( DISTINCT participant_id ) FROM participants_in_Events ;