Guest User

Untitled

a guest
Apr 22nd, 2022
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.24 KB | None | 0 0
  1. WITH combine AS
  2.     (SELECT
  3.     CAST (bikeshare_trips.start_date AS DATE) AS start_date, bikeshare_regions.name AS region, COUNT (bikeshare_trips.trip_id) AS cumulative
  4.     FROM `bigquery-public-data.san_francisco_bikeshare.bikeshare_trips` AS bikeshare_trips
  5.         INNER JOIN `bigquery-public-data.san_francisco_bikeshare.bikeshare_station_info` AS bikeshare_station_info
  6.         ON bikeshare_trips.start_station_id = bikeshare_station_info.station_id
  7.         INNER JOIN `bigquery-public-data.san_francisco_bikeshare.bikeshare_regions` AS bikeshare_regions
  8.         ON bikeshare_station_info.region_id = bikeshare_regions.region_id
  9.     WHERE
  10.         bikeshare_trips.start_date BETWEEN '2017-11-01' AND '2017-12-01' AND bikeshare_regions.name IS NOT NULL
  11.         GROUP BY 2,1
  12.         ORDER BY 1),
  13. combine_2 AS
  14.     (SELECT start_date,region, SUM (cumulative) AS sum_cumulative
  15.     FROM combine
  16.     GROUP BY 2,1)
  17. SELECT
  18.     start_date,
  19.     region,
  20.     SUM (sum_cumulative) OVER (PARTITION BY region ORDER BY start_date) AS total_trips_cummulative
  21. FROM combine_2
  22. ORDER BY 2 DESC, 1 DESC;
Advertisement
Add Comment
Please, Sign In to add comment