Skip to content

SQL query to get the latest price from the data?

I have this data in my Oracle table: 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 …

Sum last two records including last record of a group

In SQL Server 2017, how do I sum the last two records and show the last record in a single query? Expected output: I tried using SUM with LAST_VALUE with ORDER BY Answer You can filter out rows by using the ROW_NUMBER() window function, as in: See SQL Fiddle.