Skip to content
Advertisement

pgsql: filter column to get latest value

I have below query to pivot, how to get status value filtered on latest updated_on row for each obj_key

Table/data is here dbfiddle

i was trying by first_value(status) OVER( ORDER BY updated_on) AS status but no luck

Can we get status as per max(updated_on) for each obj_key ?

Advertisement

Answer

Try this version, the first_value(status) is changed to last_value(status) and the OVER W has been moved to the aggregate, so inside of the COALESCE statements.

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