Created
May 6, 2025 19:37
-
-
Save Arqentum/7f72a16dc8cc945356bde1258619f3da to your computer and use it in GitHub Desktop.
#BiqQuery #SQL back and forward fill
This file contains hidden or 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
| with tt1 as (select 1 as time, null as val union all | |
| select 2, 1 union all | |
| select 3, null union all | |
| select 4, null union all | |
| select 5, null union all | |
| select 6, 0 union all | |
| select 7, null union all | |
| select 8, null | |
| ) | |
| select * | |
| , first_value(val ignore nulls) over (order by time) fv | |
| , last_value(val ignore nulls) over (order by time asc) as fill_down | |
| , last_value(val ignore nulls) over (order by time desc) as fill_down | |
| , first_value(val ignore nulls) over (order by time RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) fv2 | |
| from tt1 | |
| where true | |
| order by time | |
| ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment