summaryrefslogtreecommitdiff
path: root/views
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2015-03-03 11:54:10 +0100
committeremkael <emkael@tlen.pl>2015-03-03 11:54:10 +0100
commitffd9d4fb6706e609a16b3a5a2fffe0959fd845d3 (patch)
tree32d28a2d9254a18842312dd8e865b40068a6187b /views
parent6c73fedbaad194fa47d92182f4005b963313a114 (diff)
* career length stats
* http://ergast.com/mrd/bugs/comment-page-2#comment-12128
Diffstat (limited to 'views')
-rw-r--r--views/career_length.sql10
1 files changed, 10 insertions, 0 deletions
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;