SQLserver 两表关联查询分页,求大神帮写下SQL语句

$sql = "select h.[医院名称],k.[科室名称],k.[科室编号],k.id,k.kid from [医院表] as h right join [科室表] as k on k.hid = h.hid";

页大小 $page_size = 3;
总记录数 $c;
哪位大神能帮我写个分页的SQL语句 万分感谢

第1个回答  2014-08-07
--授之以渔
--方法 1:  此方法适用于 SQL Server 2000/2005/2008 
-- Pager the record 
-- Note: N 代表要求查询的第 n 页的记录,X 表示每一页有 x 条记录。 
select top X * from tb 
 where pk_col not in (select top (N-1)*X pk_col from tb)  
-- Demo 
select top 10 * from persons 
 where username not in(select top ((3-1)*10) username from persons)

追问

这是单表的分页吧 两个表或者多表关联分页要如何写呢 能写个例子吗

相似回答