db2分頁sql語法
int startPage=1 //起始頁
int endPage; //終止頁
int pageSize=5; //頁大小
int pageNumber=1 //請求頁
startPage=(pageNumber-1)*pageSize+1
endPage=(startPage+pageSize);
select * from (select 字段1,字段2,字段3,字段4,字段5,rownumber()
over(order by 排序字段 asc ) as rowid from 表名 )as a where a.rowid
>= startPage AND a.rowid
swdjrq,bgbs,bgcz,bgrq,swdjjgdm,orgdeptname,nsrsbh ,rownumber()
over(order by dslsid asc ) as rowid from FR_V_DSLS )as a
where a.rowid BETWEEN 1 AND 6
不好意思,犯了個低級錯誤,上面的sql語句是有誤的,原因在於對
between and的錯誤理解
本人記得between and是包含前者,不包含後者,實驗表明,
between and 前後兩者都包含。
所以上述語句應修改為:
select * from (select dslsid,zzjgdm,frmc,frlx,mc,frzs,
fddbrxm,clrq,frzch,nsrglm,swdjrq,
bgbs,bgcz,bgrq,swdjjgdm,orgdeptname,nsrsbh ,rownumber()
over(order by dslsid asc ) as rowid from FR_V_DSLS )as
a where a.rowid >= 1 AND a.rowid < 6
留著上面的語句加深印象。