I have this data sample :
card service date value
1 1 27-10-2014 5
1 1 28-10-2014 5
1 1 28-10-2014 6
What is the best approach to return the last row (most recent and in case of ties the higher value)?
Thanks in advance.
Edited:
card service date value
1 1 27-10-2014 5
1 1 28-10-2014 5
1 1 28-10-2014 6
2 2 29-10-2014 7
This should have returned the 3rd and 4th record.
Thanks for all the replies. But today I have a small change request. I will have a column with Percentage and another column with a Char to indicate if is a value or a percentage.
I am trying to do something like this:
select card,
service,
max(date),
case when type = 'v'
then
MAX(value) KEEP (
dense_rank first order by date desc
)
else
max(percentage) valor keep (
dense_rank first order by date desc
) end
from table
group by card,
service;
But I am getting ORA-00979: not a GROUP BY expression