Last active
January 19, 2022 10:09
-
-
Save sh16ma/371f002770da8ceec597e7f817d15212 to your computer and use it in GitHub Desktop.
#🔎 #BigQuery #日数差 #ウィンドウ関数 #ウィンドウフレーãƒ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#standaardSQL | |
select | |
Location | |
, datetime_diff(new_date, old_date, day) as days_diff | |
from( | |
select | |
-- * | |
Date | |
, Location | |
, first_value(Date)over( | |
partition by Location | |
order by Date asc) as old_date | |
, last_value(Date)over( | |
partition by Location | |
order by Date asc | |
rows between UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING ) as new_date | |
from | |
`pj.ds.weatherAUS` | |
) | |
group by | |
Location | |
, days_diff | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment