Skip to content

Instantly share code, notes, and snippets.

@bAcheron
Last active January 8, 2020 05:40
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 bAcheron/28b1c572aaa2da31e43044a743e7b1f3 to your computer and use it in GitHub Desktop.
Save bAcheron/28b1c572aaa2da31e43044a743e7b1f3 to your computer and use it in GitHub Desktop.
Select NTILE(4) over (order by rn),
avg_total_rides,
station_id,
num_bikes_available
from
(
select
row_number() over (order by avg_total_rides desc) rn,
t1.station_id,
avg_total_rides,
num_bikes_available
from
(
select
avg(total_rides) avg_total_rides,
station_id
from
(
select
sum(total_rides) total_rides,
start_date,
c."start station id" station_id
from
(
select
cast(cast(starttime as datetime) as date) start_date,
1 total_rides,
b."start station id"
from
bike_rides b
) c
group by
start_date,
c."start station id"
) d
group by
station_id
) t1
join (
select
distinct station_id,
b.num_bikes_available
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment