Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH combine AS
- (SELECT
- CAST (bikeshare_trips.start_date AS DATE) AS start_date, bikeshare_regions.name AS region, COUNT (bikeshare_trips.trip_id) AS cumulative
- FROM `bigquery-public-data.san_francisco_bikeshare.bikeshare_trips` AS bikeshare_trips
- INNER JOIN `bigquery-public-data.san_francisco_bikeshare.bikeshare_station_info` AS bikeshare_station_info
- ON bikeshare_trips.start_station_id = bikeshare_station_info.station_id
- INNER JOIN `bigquery-public-data.san_francisco_bikeshare.bikeshare_regions` AS bikeshare_regions
- ON bikeshare_station_info.region_id = bikeshare_regions.region_id
- WHERE
- bikeshare_trips.start_date BETWEEN '2017-11-01' AND '2017-12-01' AND bikeshare_regions.name IS NOT NULL
- GROUP BY 2,1
- ORDER BY 1),
- combine_2 AS
- (SELECT start_date,region, SUM (cumulative) AS sum_cumulative
- FROM combine
- GROUP BY 2,1)
- SELECT
- start_date,
- region,
- SUM (sum_cumulative) OVER (PARTITION BY region ORDER BY start_date) AS total_trips_cummulative
- FROM combine_2
- ORDER BY 2 DESC, 1 DESC;
Advertisement
Add Comment
Please, Sign In to add comment