SQL - How to select a row having a column with max value in Oracle

♀尐吖头ヾ 提交于 2021-01-28 12:40:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!