Created
September 12, 2018 15:52
-
-
Save joebartels/c2683b662a3e875355c21755e44a9d73 to your computer and use it in GitHub Desktop.
select km cycled by day of week
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select sum(km_cycled) as total_km_cycled, | |
case when day_of_week=0 then 'Sunday' | |
when day_of_week=1 then 'Monday' | |
when day_of_week=2 then 'Tuesday' | |
when day_of_week=3 then 'Wednesday' | |
when day_of_week=4 then 'Thursday' | |
when day_of_week=5 then 'Friday' | |
when day_of_week=6 then 'Saturday' | |
end as day | |
from cycling_entry | |
group by day_of_week; | |
-- average time: 7.75ms | |
select sum(km_cycled) as total_km_cycled, | |
case when extract(dow from date)=0 then 'Sunday' | |
when extract(dow from date)=1 then 'Monday' | |
when extract(dow from date)=2 then 'Tuesday' | |
when extract(dow from date)=3 then 'Wednesday' | |
when extract(dow from date)=4 then 'Thursday' | |
when extract(dow from date)=5 then 'Friday' | |
when extract(dow from date)=6 then 'Saturday' | |
end as day | |
from cycling_entry | |
group by extract(dow from date); | |
-- average time: 21.7ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment