oracle sql 前100条数据库,oracle/mysql/sqlserver三种数据库查询表获取表数据的前100条数据与排序时获取指定的条数....

1.oracle

获取表的前100条数据.

select * from t_stu_copy  where rownum<=100;(从1行开始取100行数据,第一行到第100行数据)

补充:先降序排序再获取第101条到第200条之间的所有记录

select * from t_stu_copy order by stuid desc where rownum between 100 and 200 ;---错误

select * from t_stu_copy where rownum between 100 and 200 order by stuid desc  ;---错误

SELECT * FROM(SELECT ROWNUM AS rowno,t.* FROM t_stu_copy t WHERE ROWNUM <= 200 ORDER BY t.stuid ) a WHERE a.rowno > 100;正确

或者:select  * from t_stu_copy where stuid between 101 and 200;

2.mysql

获取表的前100条数据.

select * from t_stu_copy limit 0,100;(从1行开始取100行数据,第一行到第100行数据)

补充:先降序排序再获取第101条到第200条之间的所有记录

select * from t_stu_copy order by stuid  limit 100,100;(从101行开始取100行数据,第101行到第200行数据)

或者:select  * from t_stu_copy where stuid between 101 and 200;

3.sqlserver

获取表的前100条数据.

select top 100 * from t_stu_copy ;


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部