如何在排序后仅获得结果集中的第一行? [英] How can I get just the first row in a result set AFTER ordering?
本文介绍了如何在排序后仅获得结果集中的第一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这仅给我一行(第一行):
This gives me just one row (the first one):
SELECT BLA
FROM BLA
WHERE BLA
AND ROWNUM < 2
但是,我想要最近的日期值;我可以这样制作第一行:
However, I want the most recent date val; I can make that the first row this way:
SELECT BLA
FROM BLA
WHERE BLA
ORDER BY FINALDATE DESC
但是,当我尝试混合两个部分胜利时,它不起作用-显然,仅选择第一行"逻辑会在排序依据之前发出 ,然后排序依据是随后被忽略.
When I try to mix the two partial victories, though, it doesn't work - apparently the "Select the first row only" logic fires before the order by, and then the order by is subsequently ignored.
推荐答案
此问题类似于它讨论了如何在Oracle数据库上实施MySQL限制,该限制由您的标签和发布信息决定.
It talks about how to implement a MySQL limit on an oracle database which judging by your tags and post is what you are using.
相关部分是:
select *
from
( select *
from emp
order by sal desc )
where ROWNUM <= 5;
这篇关于如何在排序后仅获得结果集中的第一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文