谢谢各位的帮忙啦!已经解决了!sql如下: select * from ( select z.*,rownum from( SELECT * FROM a p where p.frequence is not null ORDER BY p.frequence DESC ) z ) where rownum<=500 向各位再追加请教一个问题:用它查询速度实在是太慢了,能否有什么好的方法可以优化它, 提高它的查询速度!谢谢各位啦!
这个可能好点:SELECT * FROM (SELECT a.*, row_number() OVER(ORDER BY frequence desc) rn FROM a) WHERE rn < 3
from A
where rownum<101
order by frequence
根据这个frequence字段,怎么个根据? 最大的100个? 最小的100个? 还是别的?
select *
from (select rownum rn,a.* from a order by frequence desc)
where rn<=100
这种是不对的,关键是看frequence字段,例如: A表: name no frequence 张三 11 2
李四 12 2
王五 13 5
毛刘 14 8 例如是这么张表,frequence字段记录的就是每条记录查询过的次数,现在就是根据frequence来查询前
100条记录啊
(select rownum rn,a.* from a order by frequence desc)
where rn<=100
就是根据frequence的大小顺序,查询前100,具体看我给“horizonlyhw”的回复
select * from A where rownum<=100 order by frequence desc;
升序的话就把desc去掉。
p.frequence is not null ORDER BY p.frequence DESC ) z ) where rownum<=500 向各位再追加请教一个问题:用它查询速度实在是太慢了,能否有什么好的方法可以优化它, 提高它的查询速度!谢谢各位啦!