Skip to content

Instantly share code, notes, and snippets.

@lfy79001
Created May 28, 2024 10:08
Show Gist options
  • Save lfy79001/71fe2df9ce906b1745cd7e43dad85c6a to your computer and use it in GitHub Desktop.
Save lfy79001/71fe2df9ce906b1745cd7e43dad85c6a to your computer and use it in GitHub Desktop.
SELECT
wx.date,
MAX(prcp) AS prcp,
MAX(tmin) AS tmin,
MAX(tmax) AS tmax,
IF(MAX(haswx) = 'True', 'True', 'False') AS haswx
FROM (
SELECT
wx.date,
IF (wx.element = 'PRCP', wx.value/10, NULL) AS prcp,
IF (wx.element = 'TMIN', wx.value/10, NULL) AS tmin,
IF (wx.element = 'TMAX', wx.value/10, NULL) AS tmax,
IF (SUBSTR(wx.element, 0, 2) = 'WT', 'True', NULL) AS haswx
FROM
`bigquery-public-data.ghcn_d.ghcnd_2015` AS wx
WHERE
id = 'USW00094846'
AND qflag IS NULL )
GROUP BY
wx.date
ORDER BY
wx.date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment