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

sql排序取前10条

1.limit关键字是mysql中的,top关键字是ms sqlserver中的,pl/sql是oracle的客户端工具,这两个关键字在这里不适用。 2.select rownum,a.* from (select * from test order by id desc) a where rownum

MYSQL中查询表中按字段降序排列的前N条记录模式: SELECT 字段名[ , 字段名...] FROM 表名 WHERE 条件 LIMIT 数量 ORDER BY 字段名 DESC 例如: select id,name,email from test where age < 19 limit 5 order by id desc;上面例子从test表查询...

取前10条记录的sql语句写法: 1、access: select top (10) * from table1 where 1=1 2、db2: select column from table where 1=1 fetch first 10 rows only 3、mysql: select * from table1 where 1=1 limit 10 4、sql server: 读取前10条:...

SELECT C.D FROM ( SELECT C,D,ROWNUM RN FROM ( SELECT T.* FROM TABLE1 ORDER BY B DESC --降序 ) T1 ) WHERE RN

方法是: select * from (select * from t order by col1) where rownum= 2 and row_number() over(order by id) = 2 and row_number() over(order by id)

order by中指定了用id排序,至少子查询中应该包含id列吧?另外子查询用在from子句中必须为子查询设置一个别名。 select top 10 * from (select A.id,A.name,B.sex from userinfo A,sexinfo B where A.id = B.id and A.sex = B.sexid) as newtabl...

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

sql server: 前10条: select top 10 * from 表 order by 需要排序的字段 10-30: select * from (select row_number() over (order by 需要排序的字段) as id,* from 表 )a where id between 10 and 30 或者 select top 21 * from 表 where id no...

1. 这两条语句是否适用于PL/SQL? 这两条语句不是适合不适合plsql,而是不适合oracle 2.如果不适用那么还有其它更好的语句么? oracle中用来限制行数,一般都用rownum这个伪列的。 如 select * from (select * from test order by id desc ) whe...

SELECT TOP 10 * FROM 表名 ORDER BY 排序字段

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