Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Max Price Based on Date

798631Dec 11 2012 — edited Dec 11 2012
Hello,

I need to return the price of the id having the max(date).There can be multiple identical id's with different prices with diffent dates. The date is and must be <= '10-10-12'.

ID Price Dt
1234 10 09-09-12
1234 20 09-20-12
1234 15 15-10-12

I am trying to return 20, but keep getting both 10 and 20 since they are both <= 10-10-12

select id,price,dt
from table_name
where id = 1234
group by id,price,date
having max(dt) <= to_date('10-oct-2012')

How can i write this to return only 20?

Edited by: DOUBLE U on Dec 11, 2012 2:31 PM -- Changed occurences of date and action date to dt. Action date was an error.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 8 2013
Added on Dec 11 2012
8 comments
440 views