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 is the most common participant type?
assistant
SELECT participant_type_code FROM participants GROUP BY participant_type_code ORDER BY count(*) DESC LIMIT 1
human
Which services type had both successful and failure event details?
assistant
SELECT T1.service_type_code FROM services AS T1 JOIN EVENTS AS T2 ON T1.service_id = T2.service_id WHERE T2.event_details = 'Success' INTERSECT SELECT T1.service_type_code FROM services AS T1 JOIN EVENTS AS T2 ON T1.service_id = T2.service_id WHERE T2.event_details = 'Fail'
human
Which service id and type has the least number of participants?
assistant
SELECT T3.service_id , T4.Service_Type_Code FROM participants AS T1 JOIN Participants_in_Events AS T2 ON T1.Participant_ID = T2.Participant_ID JOIN EVENTS AS T3 ON T2.Event_ID = T3.Event_ID JOIN services AS T4 ON T3.service_id = T4.service_id GROUP BY T3.service_id ORDER BY count(*) ASC LIMIT 1
human
what are the event details of the services that have the type code 'Marriage'?
assistant
SELECT T1.event_details FROM EVENTS AS T1 JOIN Services AS T2 ON T1.Service_ID = T2.Service_ID WHERE T2.Service_Type_Code = 'Marriage'
human
List the service id and details for the events.
assistant
SELECT service_id , event_details FROM EVENTS
human
List the type of the services in alphabetical order.
assistant
SELECT service_type_code FROM services ORDER BY service_type_code ;