Skip to content
Advertisement

How to combine data from different variables together in SQL?

Let’s say I have data like this:

All I want to do is collect the most recent non-null value from each column and condense them into a table with each row being an entry.

Final result:

Here’s what I have but it’s not complete:

Advertisement

Answer

Related: Equivalent for Keep in Snowflake:

It could be achieved with:

Output:

ARRAY_AGG by default omits NULLs and it is sorted by timestamp descending. Once array per user_id is created it is a matter of accesing first element(element with index [0]).

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement