订单查询
订单的支付类型:线上支付、线下支付、混合支付
订单的支付状态:未支付、已支付、部分支付
现在需要分页查询所有订单记录,但不包括支付类型为线上支付,且支付状态为未支付的订单
用在分页中,不是一次性查出全部数据!
SQL如何写???
谢谢!
sql server的写法:
约定参数:page_size
:每页的条目数page
:当前页数,从1开始
select top page*page_size * from order as o1
where o1.pay_type != '线上支付' and o1.order_status = '未支付' --过滤条件
and not exist( --分页条件
select top (page-1)*page_size * from order as o2
where o1.pay_type != '线上支付' and o1.order_status = '未支付' --过滤条件
and o1.id = o2.id
)
首先,楼主应该弄清分页相关的数据:当前页(N)、显示最大条数(M);这些都是从前台获取的,需要在程序里计算一下,得到结果作为sql的参数。例如,这种情况就是查询第(N-1)M +1到地NM条数据。
用实际数字距离:N=4,M=5;就是要查询地16条到第20条数据。
mysql数据库实现:
select * form order where type <> '线上支付' and status = '未支付' limit 15, 5
Oracle数据库实现:
select * from (
select rownum as rn * from order where type <> '线上支付' and status = '未支付' and rownum >= 20 ) a where a.rn >= 16