问题
date value
18/5/2010 40
18/5/2010 20
20/5/2010 60
18/5/2010 30
17/5/2010 10
16/5/2010 40
18/5/2010 60
18/5/2010 25
Output
date value
18/5/2010 60
20/5/2010 60
I need to query for the row having max(value)(i.e. 60). So, here we get two rows. the date can be in any order
Plz do not use rownum and subquery I need a dynamic query
回答1:
I believe this is what you're looking for:
select *
from table
where value = (select max(value) from table);
回答2:
select * from (select * from table
order by value desc, date_column)
where rownum = 1;
Answering the question more specifically:
select high_val, my_key
from (select high_val, my_key
from mytable
where something = 'avalue'
order by high_val desc)
where rownum <= 1
回答3:
This works and is quite simple:
SELECT MAX(value)
FROM table
来源:https://stackoverflow.com/questions/45608862/sql-how-to-select-a-row-having-a-column-with-max-value-in-oracle