Skip to content
Advertisement

Select single value from same columns based on condition

I have below table and using oracle sql

Result

Question : Need query to get it. I have Tried MAX but not working

Advertisement

Answer

Assuming these are the only three conditions, you can use conditional aggregation:

In Oracle, you can simplify this to:

Here is a db<>fiddle.

The keep syntax is getting the last value for the status based on the timestamp.

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