From ffd9d4fb6706e609a16b3a5a2fffe0959fd845d3 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 3 Mar 2015 11:54:10 +0100 Subject: * career length stats * http://ergast.com/mrd/bugs/comment-page-2#comment-12128 --- views/career_length.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 views/career_length.sql (limited to 'views') diff --git a/views/career_length.sql b/views/career_length.sql new file mode 100644 index 0000000..e950f32 --- /dev/null +++ b/views/career_length.sql @@ -0,0 +1,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; -- cgit v1.2.3