2019-02-25
閱讀量:
753
sql查詢語句
問題描述:
訂單查詢
訂單的支付類型:線上支付、線下支付、混合支付
訂單的支付狀態(tài):未支付、已支付、部分支付
現(xiàn)在需要分頁查詢所有訂單記錄,但不包括支付類型為線上支付,且支付狀態(tài)為未支付的訂單
用在分頁中,不是一次性查出全部數(shù)據(jù)!
SQL如何實(shí)現(xiàn)?
解決方法:
sql server實(shí)現(xiàn):
約定參數(shù):
page_size:每頁的條目數(shù)
page:當(dāng)前頁數(shù),從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
);
當(dāng)前頁(N)、顯示最大條數(shù)(M);這些都是從前臺(tái)獲取的,需要在程序里計(jì)算一下,得到結(jié)果作為sql的參數(shù)。例如,這種情況就是查詢第(N-1)M +1到地NM條數(shù)據(jù)。
用實(shí)際數(shù)字距離:N=4,M=5;就是要查詢地16條到第20條數(shù)據(jù)。
mysql實(shí)現(xiàn):
select * form order where type <> '線上支付' and status = '未支付' limit 15, 5;
Oracle數(shù)據(jù)庫實(shí)現(xiàn):
select * from (
select rownum as rn * from order where type <> '線上支付' and status = '未支付' and rownum >= 20 ) a where ;






評(píng)論(0)


暫無數(shù)據(jù)
CDA考試動(dòng)態(tài)
CDA報(bào)考指南
推薦帖子
0條評(píng)論
0條評(píng)論
0條評(píng)論
0條評(píng)論