1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| select * from summer_medals;
select row_number() over() as row_num , * from summer_medals;
select row_number() over() as row_num , year from (select distinct year from summer_medals order by year asc) as years order by year asc;
select * from summer_medals;
with athlete_medals as ( select athlete , count(*) medal_counts from summer_medals group by athlete ) select athlete , medal_counts , row_number() over(order by medal_counts desc) as row_num from athlete_medals order by medal_counts desc limit 10;
select * from summer_medals; select distinct event, discipline, athlete, gender from summer_medals where event = '200M' and gender = 'Women' and medal = 'gold';
select year , country as champion from summer_medals where discipline = 'Weightlifting' and event = '69KG' and gender = 'Men' and medal = 'Gold';
with weightligting_69_men_gold as ( select year , country as champion from summer_medals where discipline = 'Weightlifting' and event = '69KG' and gender = 'Men' and medal = 'Gold' )
select year , champion , LAG(champion) over(order by year asc) as last_champion from weightligting_69_men_gold order by year asc;
with Athletics_200_Women_Gold as ( select year , athlete as champion from summer_medals where discipline = 'Athletics' and event = '200M' and gender = 'Women' and medal = 'Gold' )
select year , champion , lag(champion) over(order by year asc) as last_champion from Athletics_200_Women_Gold order by year asc;
WITH Discus_Gold_Medal AS ( SELECT Year, Event, Country AS Champion FROM summer_medals WHERE Year IN (2004, 2008, 2012) AND Gender = 'Men' AND Medal = 'Gold' AND Event IN ('Discus Throw', 'Triple Jump') AND Gender = 'Men') SELECT YEAR, Event, Champion, LAG(Champion) OVER (ORDER BY Event ASC, Year ASC) AS Last_Champion FROM Discus_Gold_Medal ORDER BY Event ASC, Year ASC;
WITH Discus_Gold_Medal AS ( SELECT Year, Event, Country AS Champion FROM summer_medals WHERE Year IN (2004, 2008, 2012) AND Gender = 'Men' AND Medal = 'Gold' AND Event IN ('Discus Throw', 'Triple Jump') AND Gender = 'Men') SELECT YEAR, Event, Champion, LAG(Champion) OVER (PARTITION BY Event ORDER BY Event ASC, Year ASC) AS Last_Champion FROM Discus_Gold_Medal ORDER BY Event ASC, Year ASC;
|