human
Schema:
race (Race_ID, Name, Class, Date, Track_ID)
track (Track_ID, Name, Location, Seating, Year_Opened)
Please answer with SQL.
assistant
Sure, I understand.
human
Show the name of track and the number of races in each track.
assistant
SELECT T2.name , count(*) FROM race AS T1 JOIN track AS T2 ON T1.track_id = T2.track_id GROUP BY T1.track_id
human
What are the distinct classes that races can have?
assistant
SELECT DISTINCT CLASS FROM race
human
Show name, class, and date for all races.
assistant
SELECT name , CLASS , date FROM race
human
What is the race class with most number of races.
assistant
SELECT CLASS FROM race GROUP BY CLASS ORDER BY count(*) DESC LIMIT 1
human
List the race class with at least two races.
assistant
SELECT CLASS FROM race GROUP BY CLASS HAVING count(*) >= 2
human
Show the race class and number of races in each class.
assistant
SELECT CLASS , COUNT( * ) FROM race GROUP BY CLASS ;