summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--views/full_season_drivers.sql10
1 files changed, 10 insertions, 0 deletions
diff --git a/views/full_season_drivers.sql b/views/full_season_drivers.sql
index 0ad0bbd..2ab10b9 100644
--- a/views/full_season_drivers.sql
+++ b/views/full_season_drivers.sql
@@ -32,3 +32,13 @@ CREATE VIEW full_season_drivers AS
JOIN driver_season_races
ON (season_races.races = driver_season_races.races)
AND (season_races.year = driver_season_races.year);
+
+-- average grid age for every race
+DROP VIEW IF EXISTS average_grid_age;
+CREATE VIEW average_grid_age AS
+ SELECT AVG(DATEDIFF(races.date, drivers.dob)) average_age,
+ CONCAT(races.year, ' ', races.name) race, races.date
+ FROM driver_races
+ JOIN races ON driver_races.raceId = races.raceId
+ JOIN drivers ON drivers.driverId = driver_races.driverId
+ GROUP BY races.raceId;