sql - LAST_VALUE() with ASC and FIRST_VALUE with DESC return different results -


i have trouble using last_value() window function in google bigquery.

in understanding, following 2 columns should return same results, return different results , seems 1 first_value() correct.

select   first_value(status) on (partition userid order timestamp desc),    last_value(status) on (partition userid order timestamp asc)   [table] 

did make mistake?

there's subtlety on how over() functions work when have (order by): work incrementally.

see query:

select x, y,         first_value(x) over(order y) first,         last_value(x) over(order y desc) last,        sum(x) over() plain_sum_over,         sum(x) over(order y) sum_over_order (select 1 x, 1 y),(select 2 x, 2 y),(select 3 x, 3 y),(select 4 x, 4 y) 

enter image description here

the plain_sum_over , sum_over_order reveal secret: order incremental results - , that's witnessing in results.


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -