Oralce分页查询
对于单表查询:
select *
from (select temp.*,rownum rn
from (select * from t_ap_ap_app) temp)
where rn between 21 and 40;
select rn,temp1.*
from (select temp.*, rownum rn
from (select * from t_ap_ap_app order by app_code desc) temp
where rownum<=40) temp1
where rn>=21;
对于多表查询:
select *
from (select temp.*, rownum rn
from (select app.app_code as app_code, app.app_status as status
from t_tp_app app left join t_tp_app_line appLine
on app.app_code=appLine.app_code) temp
where rownum<=40)
where rn>=21;
SQL 2008分页查询
对于单表查询:
select *
from (select ROW_NUMBER() over(order by temp.code desc) as rownum,temp.*
from (select * from T_AP_ORDER) as temp) as temp1
where temp1.rownum between 21 and 40 ;
对于多表查询:
select *
from(select row_number() over(order by temp.code desc) as rownum,temp.*
from (select od.CODE as code,od.STATUS as status
from T_AP_ORDER as od left join T_AP_ORDER_LINE as odLine
on od.ID=odLine.ORDER_ID) as temp) temp1
where rownum between 21 and 40;