CREATE TABLE circuits (
    circuitId NUMBER PRIMARY KEY,
    circuitRef TEXT,
    name TEXT,
    location TEXT,
    country TEXT,
    lat NUMBER,
    lng NUMBER,
    alt NUMBER,
    url TEXT
);
CREATE TABLE races (
    raceId NUMBER PRIMARY KEY,
    year NUMBER,
    round NUMBER,
    circuitId NUMBER,
    name TEXT,
    date TEXT,
    time TEXT,
    url TEXT,
    FOREIGN KEY ("circuitId") REFERENCES circuits("circuitId")
);
CREATE TABLE drivers (
    driverId NUMBER PRIMARY KEY,
    driverRef TEXT,
    number NUMBER,
    code TEXT,
    forename TEXT,
    surname TEXT,
    dob TEXT,
    nationality TEXT,
    url TEXT
);
CREATE TABLE status (
    statusId NUMBER PRIMARY KEY,
    status TEXT
);
CREATE TABLE seasons (
    year NUMBER PRIMARY KEY,
    url TEXT
);
CREATE TABLE constructors (
    constructorId NUMBER PRIMARY KEY,
    constructorRef TEXT,
    name TEXT,
    nationality TEXT,
    url TEXT
);
CREATE TABLE constructorStandings (
    constructorStandingsId NUMBER PRIMARY KEY,
    raceId NUMBER,
    constructorId NUMBER,
    points NUMBER,
    position NUMBER,
    positionText TEXT,
    wins NUMBER,
    FOREIGN KEY ("raceId") REFERENCES races("raceId"),
    FOREIGN KEY ("constructorId") REFERENCES constructors("constructorId")
);
CREATE TABLE results (
    resultId NUMBER PRIMARY KEY,
    raceId NUMBER,
    driverId NUMBER,
    constructorId NUMBER,
    number NUMBER,
    grid NUMBER,
    position NUMBER,
    positionText TEXT,
    positionOrder NUMBER,
    points NUMBER,
    laps NUMBER,
    time TEXT,
    milliseconds NUMBER,
    fastestLap NUMBER,
    rank NUMBER,
    fastestLapTime TEXT,
    fastestLapSpeed TEXT,
    statusId NUMBER,
    FOREIGN KEY ("driverId") REFERENCES drivers("driverId"),
    FOREIGN KEY ("raceId") REFERENCES races("raceId"),
    FOREIGN KEY ("constructorId") REFERENCES constructors("constructorId")
);
CREATE TABLE driverStandings (
    driverStandingsId NUMBER PRIMARY KEY,
    raceId NUMBER,
    driverId NUMBER,
    points NUMBER,
    position NUMBER,
    positionText TEXT,
    wins NUMBER,
    FOREIGN KEY ("driverId") REFERENCES drivers("driverId"),
    FOREIGN KEY ("raceId") REFERENCES races("raceId")
);
CREATE TABLE constructorResults (
    constructorResultsId NUMBER PRIMARY KEY,
    raceId NUMBER,
    constructorId NUMBER,
    points NUMBER,
    status NUMBER,
    FOREIGN KEY ("raceId") REFERENCES races("raceId"),
    FOREIGN KEY ("constructorId") REFERENCES constructors("constructorId")
);
CREATE TABLE qualifying (
    qualifyId NUMBER PRIMARY KEY,
    raceId NUMBER,
    driverId NUMBER,
    constructorId NUMBER,
    number NUMBER,
    position NUMBER,
    q1 TEXT,
    q2 TEXT,
    q3 TEXT,
    FOREIGN KEY ("driverId") REFERENCES drivers("driverId"),
    FOREIGN KEY ("raceId") REFERENCES races("raceId"),
    FOREIGN KEY ("constructorId") REFERENCES constructors("constructorId")
);
CREATE TABLE pitStops (
    raceId NUMBER PRIMARY KEY,
    driverId NUMBER,
    stop NUMBER,
    lap NUMBER,
    time TEXT,
    duration TEXT,
    milliseconds NUMBER,
    FOREIGN KEY ("driverId") REFERENCES drivers("driverId"),
    FOREIGN KEY ("raceId") REFERENCES races("raceId")
);
CREATE TABLE lapTimes (
    raceId NUMBER PRIMARY KEY,
    driverId NUMBER,
    lap NUMBER,
    position NUMBER,
    time TEXT,
    milliseconds NUMBER,
    FOREIGN KEY ("driverId") REFERENCES drivers("driverId"),
    FOREIGN KEY ("raceId") REFERENCES races("raceId")
);

Question: What is the average fastest lap speed for races held after 2004, for each race, ordered by year?
SQL: SELECT avg(T2.fastestlapspeed) ,  T1.name ,  T1.year FROM races AS T1 JOIN results AS T2 ON T1.raceid = T2.raceid WHERE T1.year > 2014 GROUP BY T1.name ORDER BY T1.year

Question: Find the id, forename and number of races of all drivers who have at least participated in two races?
SQL: SELECT T1.driverid ,  T1.forename ,  count(*) FROM drivers AS T1 JOIN results AS T2 ON T1.driverid = T2.driverid JOIN races AS T3 ON T2.raceid = T3.raceid GROUP BY T1.driverid HAVING count(*)  >=  2

Question: What is the id, forename, and number of races for all drivers that have participated in at least 2 races?
SQL: SELECT T1.driverid ,  T1.forename ,  count(*) FROM drivers AS T1 JOIN results AS T2 ON T1.driverid = T2.driverid JOIN races AS T3 ON T2.raceid = T3.raceid GROUP BY T1.driverid HAVING count(*)  >=  2

Question: Find the driver id and number of races of all drivers who have at most participated in 30 races?
SQL: SELECT T1.driverid ,  count(*) FROM drivers AS T1 JOIN results AS T2 ON T1.driverid = T2.driverid JOIN races AS T3 ON T2.raceid = T3.raceid GROUP BY T1.driverid HAVING count(*)  <=  30

Question: For each id of a driver who participated in at most 30 races, how many races did they participate in?
SQL: SELECT T1.driverid ,  count(*) FROM drivers AS T1 JOIN results AS T2 ON T1.driverid = T2.driverid JOIN races AS T3 ON T2.raceid = T3.raceid GROUP BY T1.driverid HAVING count(*)  <=  30

Question: Find the id and surname of the driver who participated the most number of races?
SQL: SELECT T1.driverid ,  T1.surname FROM drivers AS T1 JOIN results AS T2 ON T1.driverid = T2.driverid JOIN races AS T3 ON T2.raceid = T3.raceid GROUP BY T1.driverid ORDER BY count(*) DESC LIMIT 1

Question: What are the ids and last names of all drivers who participated in the most races?
SQL: SELECT T1.driverid ,  T1.surname FROM drivers AS T1 JOIN results AS T2 ON T1.driverid = T2.driverid JOIN races AS T3 ON T2.raceid = T3.raceid GROUP BY T1.driverid ORDER BY count(*) DESC LIMIT 1