human
Schema:
swimmer (ID, name, Nationality, meter_100, meter_200, meter_300, meter_400, meter_500, meter_600, meter_700, Time)
stadium (ID, name, Capacity, City, Country, Opening_year)
event (ID, Name, Stadium_ID, Year)
record (ID, Result, Swimmer_ID, Event_ID)
Please answer with SQL.
assistant
Sure, I understand.
human
Can you list the swimmer names and their times?
assistant
SELECT name , time FROM swimmer;
human
Hmm, I also want to know their record times and the related events.
assistant
SELECT t1.time , t2.event_id FROM swimmer AS t1 JOIN record AS t2 ON t1.id = t2.swimmer_id;
human
Please tell me the name of the swimmer who has at least 2 records.
assistant
SELECT t1.name FROM swimmer AS t1 JOIN record AS t2 ON t1.id = t2.swimmer_id GROUP BY t2.swimmer_id HAVING COUNT( * ) > = 2 ;