blob: e950f326d9b4c94b41c578e50b8ca1abc168c1e2 (
plain)
1
2
3
4
5
6
7
8
9
10
|
CREATE VIEW career_length AS
SELECT drivers.driverId,
COUNT(DISTINCT(results.raceId)) AS career_races,
DATEDIFF(MAX(races.date), MIN(races.date)) + 1 AS career_days,
DATEDIFF(MIN(races.date), drivers.dob) AS first_race_age,
DATEDIFF(MAX(races.date), drivers.dob) AS last_race_age
FROM results
JOIN races ON races.raceId = results.raceId
JOIN drivers ON drivers.driverId = results.driverId
GROUP BY results.driverId;
|