Skip to content

Instantly share code, notes, and snippets.

@JavierGRP
Created July 29, 2023 15:30
Show Gist options
  • Save JavierGRP/bbdb91a101b0751e0bb01acbe70f44cb to your computer and use it in GitHub Desktop.
Save JavierGRP/bbdb91a101b0751e0bb01acbe70f44cb to your computer and use it in GitHub Desktop.
CREATE MATERIALIZED VIEW times_in_position_one AS
SELECT
CONCAT(d.forename, ' ', d.surname) AS driver,
SUM(f1.pos) AS num_of_pos_1_laps
FROM f1_lap_times f1
INNER JOIN drivers d ON f1.driver_id = d.driver_id
INNER JOIN races r ON f1.race_id = r.race_id
WHERE f1.pos = 1
GROUP BY CONCAT(d.forename, ' ', d.surname)
ORDER BY SUM(f1.pos) DESC
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment