Conditional selection from a table Oracle SQL

0

I have a table with columns value, id, h (hierarchy) and date columns. A snapshot of it looks like this:

value | id  | h  | date 
---   |---  |--- |------------
 1.0  | 32  | 0  | Jul 3, 2017
 0.0  | 54  | 1  | Jul 2, 2017
 3.5  | 178 | 2  | Jul 3, 2017
 3.4  | 178 | 2  | Jul 1, 2017

This table has no primary key (aka there are multiple records for each value, id, h, or date). id and h have one to one relationship.

I want to write a query so that assuming today is Jul 3, it will return a value for each id for today, ordered by h, and showing null value if there is no record for today for that id. aka like this

value | id  | h  
---   |---  |--- 
 1.0  | 32  | 0  
 null | 54  | 1  
 3.5  | 178 | 2  

Link: Conditional selection from a table Oracle SQL
Source: Stack Sql

Share.

About Author

Leave A Reply