diff options
author | emkael <emkael@tlen.pl> | 2015-03-31 10:32:44 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2015-03-31 10:32:44 +0200 |
commit | e487a4338ac483a2374852ab8a26013a350c6626 (patch) | |
tree | b3c97c6164b64a8721b98dac32d02fe1b92e3c80 | |
parent | 7d157967431af94910e2dc0d8628ac09fd07519d (diff) |
* summary view of WDC teammates
-rw-r--r-- | views/champion_teammates.sql | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/views/champion_teammates.sql b/views/champion_teammates.sql new file mode 100644 index 0000000..ac965ae --- /dev/null +++ b/views/champion_teammates.sql @@ -0,0 +1,17 @@ +-- summary of double WDC teammate pairings +-- requires: world_drivers_champions (champions.sql), +-- teammates (teammates.sql) +DROP VIEW IF EXISTS champion_champion_teammates; +CREATE VIEW champion_champion_teammates AS + SELECT races.year, CONCAT(wdc.forename, ' ', wdc.surname) driver1, + COUNT(DISTINCT(wdc.year)) wdc_count1, + CONCAT(wdc2.forename, ' ', wdc2.surname) driver2, + COUNT(DISTINCT(wdc2.year)) wdc_count2 + FROM teammates + JOIN races ON races.raceId = teammates.raceId + JOIN world_drivers_champions wdc + ON wdc.driverId = teammates.driver1 AND wdc.year < races.year + JOIN races r2 ON r2.raceId = teammates.raceId + JOIN world_drivers_champions wdc2 + ON wdc2.driverId = teammates.driver2 AND wdc2.year < races.year + GROUP BY races.year, wdc.forename, wdc.surname, wdc2.forename, wdc2.surname; |