Skip to content

Instantly share code, notes, and snippets.

@lfy79001
Created April 30, 2024 16:56
Show Gist options
  • Save lfy79001/68d4986afbeabd56dc57512b3502903f to your computer and use it in GitHub Desktop.
Save lfy79001/68d4986afbeabd56dc57512b3502903f to your computer and use it in GitHub Desktop.
WITH bicycle_rentals AS (
SELECT
COUNT(starttime) as num_trips,
EXTRACT(DATE from starttime) as trip_date
FROM `bigquery-public-data.new_york_citibike.citibike_trips`
GROUP BY trip_date
),
rainy_days AS
(
SELECT
date,
(MAX(prcp) > 5) AS rainy
FROM (
SELECT
wx.date AS date,
IF (wx.element = 'PRCP', wx.value/10, NULL) AS prcp
FROM
`bigquery-public-data.ghcn_d.ghcnd_2016` AS wx
WHERE
wx.id = 'USW00094728'
)
GROUP BY
date
)
SELECT
ROUND(AVG(bk.num_trips)) AS num_trips,
wx.rainy
FROM bicycle_rentals AS bk
JOIN rainy_days AS wx
ON wx.date = bk.trip_date
GROUP BY wx.rainy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment