日期:2014-05-17  浏览次数:20533 次

【求助】 多表连接分页查询SQL语句

三个表内连接查询,报销单表中有3个外键,两个在person表中,一个在diction表中。
select语句如下

select e.expid,e.explain,e.subdate,e.account,e.state,e.perId,e.exaPerId,
p1.pername as pername, p2.pername as exapername,d.content as statestr
from expense as e
inner join person as p1 on (e.perid = p1.perid)
inner join person as p2 on (e.exaperid = p2.perid)
inner join diction as d on (e.state=d.keyword)
where explain like '%交通%'

SQL入门者求助:
    我想对这条SQL语句进行分页 请问该怎么写?

谢谢!!
------最佳解决方案--------------------

大概
;with c as (
select rn=row_number() over(order by x.xx),* from tb x
)
select * from c where rn between @a and @b;

可以
select top xx * from (select top yy * from tb order by id asc) a order by id desc

------其他解决方案--------------------
引用:
SQL code?123456789大概;with c as (select rn=row_number() over(order by x.xx),* from tb x)select * from c where rn between @a and @b; 可以select top xx * from (select top yy * from tb order by……


谢谢正男兄~