Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joebartels/c2683b662a3e875355c21755e44a9d73 to your computer and use it in GitHub Desktop.
Save joebartels/c2683b662a3e875355c21755e44a9d73 to your computer and use it in GitHub Desktop.
select km cycled by day of week
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