clwn.net
当前位置:首页 >> sql排序取前10条 >>

sql排序取前10条

with a as( select *,row_number() over(order by ColA) rn from tabA) select * from a where rn>=10 and rn

oracle: select * from tab where rownum

直接用order by 和top结合的语句就可以实现。 创建表及插入数据: create table test(id int,name varchar(20))insert into test values (1,'百度知道团长')insert into test values (3,'du小智')insert into test values (4,'du小佑')insert in...

可以通过row_number函数来实现。 如test表中数据如下: 现在要查询按年龄由大到小的第5-10位的人员名单,可用如下语句: select t.id,t.name,t.age from(select row_number() over(order by age desc) as rn,id,name,age from test) twhere rn b...

两者差异在于语法不同。 sqlserver取前十条可用top或row_number来实现,但oracle中只能用row_number来实现。 如表中数据: 现在要求按照ID倒序,取出前十位: oracle中执行方法: select t.id,t.name from(select test.*,row_number() over (ord...

很简单,首先你先排好序在取前十条记录SELECT * FROM (SELECT o.* FROM T_Operator o ORDER BY createtime) WHERE ROWNUM

1. Oracle数据库 SELECT * FROM TABLENAME WHERE ROWNUM

--SQL Server 2000 select top (5) * from ( select top 15 * from 表 order by 排序列 desc ) as a order by 排序列 desc --SQL Server 2005,2008,2008R2,2012通用方法 select * from ( select *,row_number() over (order by 排序列 desc) as ...

一楼逻辑有问题,这个SQL是先在表中取出前10行,在进行排序; 应该先对表排序,在取出前10行; select * from a (select * from table order by xxx) a where rownum

SELECT top 1 a.TRANS_DATE FROM a WHERE rownum = 1 ORDER BY to_date(to_char(a.TRANS_DATE,'yyyy/MM/dd'),'yyyy/MM/dd') DESC ;

网站首页 | 网站地图
All rights reserved Powered by www.clwn.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com