我在参考以下问题的基础上进行构建: SQL - 如何选择具有最大值列的行
该问题涉及到如何使用SQL语句选择具有最大值列的行。
我们可以在Sujee提供的答案基础上进一步探讨:date value 18/5/2010, 1 pm 40 18/5/2010, 2 pm 20 18/5/2010, 3 pm 60 18/5/2010, 4 pm 30 18/5/2010, 5 pm 60 18/5/2010, 6 pm 25
i need to query for the row having max(value)(i.e. 60). So, here we get two rows. From that, I need the row with the lowest time stamp for that day(i.e 18/5/2010, 3 pm -> 60)
select high_val, my_key
from (select high_val, my_key
from mytable
where something = 'avalue'
order by high_val desc)
where rownum <= 1
如果数据有第三列“category”。date value category
18/5/2010, 1 pm 40 1
18/5/2010, 2 pm 20 1
18/5/2010, 3 pm 60 1
18/5/2010, 4 pm 30 2
18/5/2010, 5 pm 60 2
18/5/2010, 6 pm 25 2
提供信息 - 我正在使用Oracle,并尝试避免嵌套连接(因此使用了rownum技巧)
目标是通过分类分组,得到相同的答案