Skip to content
Advertisement

SQL query to get the latest price from the data?

I have this data in my Oracle table:

enter image description here

In this table, I have multiple products with having product_id and price at a particular time.

I want to write a SQL query to get latest price of each product based on the TIME column (Oracle – Long Type).

But here is the problem, for our table price monitoring for the product starts at 23:00 previous date.

Output required: when I passed 2-Dec-2019 as parameter into the SQL query

enter image description here

How can I do this with a SQL query? Or do I need to write a stored procedure for it, based on if and else condition?

Thanks in advance.

Advertisement

Answer

We can try using ROW_NUMBER for this requirement:

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