[数据库汇总]-- 数据库分页查询技术以及实现查询随机数

一、oracle 分页支持:rownum关键字

 select s.* from ( select p.*,rownum rm  from ( select  t.* from t_user t) p ) s where rm between 2 and 8 ;

注意查询时,用问号替代

select s.* from ( select p.*,rownum rm  from ( select  t.* from t_user t) p ) s where rm between ? and ? ;

pstm.setInt(1, (nowPage-1)*sizePage+1);

pstm.setInt(2, nowPage*sizePage);

备注:随机查询的产生

select t.* from (select s.* ,rownum rm from (select * from t_category where c_level=2  order by dbms_random.value  )  s )t  where  rm between 2 and 4;

二、mysql 分页支持:limit关键字

select * from t_user limit 2,8;

注意查询时,2和8用占位符号替代

select * from t_user limit ?,?;

 pstm.setInt(1, (nowPage-1)*sizePage);  //代表nowPage下的第一条开始数据
         pstm.setInt(2, nowPage*sizePage);       //代表sizePage下的最后一条数据

备注:mysql随机查询

select * from course35 where cname='数学'order by rand() limit 1,2;

三、sql server分页支持 :top关键字

select top 10 *  from 表名                                                                              --查询显示0-10条记录(10条)
	select top 10 *  from 表名  where 主键 not in(select top 10 表名 from 主键); --查询显示11-20条记录(10条)
	select top 10 *  from 表名 where  主键 not in(select top 20 表名 from 主键); --查询显示21-30条记录(10条)
	select top 10 *  from 表名 where  主键 not in(select top 30 表名 from 主键);  --查询显示31-40条记录 (10条)	select top 10 *  from 表名  where 主键 not in(select top 10 表名 from 主键); --查询显示11-20条记录(10条)
	select top 10 *  from 表名 where  主键 not in(select top 20 表名 from 主键); --查询显示21-30条记录(10条)
	select top 10 *  from 表名 where  主键 not in(select top 30 表名 from 主键);  --查询显示31-40条记录 (10条)
备注:sql server 随机查询
select top 10 * from t_user order by newid();order by newid();

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

往事随风ing

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值