sql - How to get the first not null value from a column of values in Big Query? -


i trying extract first not null value column of values based on timestamp. can share thoughts on this. thank you.

what have tried far?

first_value( column ) on ( partition id order timestamp)  

input :-

id,column,timestamp 1,null,10:30 1,null,10:31 1,'xyz',10:32 1,'def',10:33 2,null,11:30 2,'abc',11:31  output(expected) :- 1,'xyz',10:30 1,'xyz',10:31 1,'xyz',10:32 1,'xyz',10:33 2,'abc',11:30 2,'abc',11:31 

try old trick of string manipulation:

select  id,   column,   ttimestamp,   ltrim(right(ccolumn,20)) ccolumn,   (select   id,   column,   ttimestamp,   min(concat(rpad(if(column null, '9999999999999999',string(ttimestamp)),20,'0'),lpad(column,20,' '))) on (partition id) ccolumn (    select     *   (select 1 id, string(null) column, 0.4375 ttimestamp),         (select 1 id, string(null) column, 0.438194444444444 ttimestamp),         (select 1 id, 'xyz' column, 0.438888888888889 ttimestamp),         (select 1 id, 'def' column, 0.439583333333333 ttimestamp),         (select 2 id, string(null) column, 0.479166666666667 ttimestamp),         (select 2 id, 'abc' column, 0.479861111111111 ttimestamp) )) 

Comments