I want to aggregate on some fields and get any not null value on others. To be more precise the query looks something like:
SELECT id, any_value(field1), any_value(field2) FROM mytable GROUP BY ID
and the columns are like:
ID | field1 | field 2
-----------------
id | null | 3
id | 1 | null
id | null | null
id | 2 | 4
and the output can be like (id, 1,4)
or (id,2,4)
or ... but not something like (id, 1, null)
I can't find in the docs if any_value()
is guaranteed to return a not null row if there is one (although it did so in my experiments) or may return a row with null
value even if there are some not null values.
Does any_value()
perform the task I described? If not what way to you suggest for doing it?