积极答复者
sql server rownum 多表连接分页查询

问题
答案
-
不晓得有没有弄错你的意思,有兴趣可以参考下列的T-SQL:
declare @t1 table (col1 int,col2 int) declare @t2 table (col3 int, col4 int) declare @t3 table (col5 int, col6 int) insert into @t1 values (1,33),(2,22),(3,11) insert into @t2 values (100,1),(200,2),(300,3) insert into @t3 values (1000,100),(2000,200),(3000,300) select * from ( select ROW_NUMBER() OVER (ORDER BY col2) as rownum,* from @t1 a inner join @t2 b on a.col1 = b.col4 inner join @t3 c on b.col3 = c.col6 ) t where rownum between 2 and 3
如果你是SQL SERVER 2012 可以用Order By 子句的新功能来做分页,像是下列的链接:
http://www.dotblogs.com.tw/terrychuang/archive/2012/06/25/73036.aspx
以上說明若有錯誤請指教,謝謝。
http://www.dotblogs.com.tw/terrychuang/- 已标记为答案 Tony xiaoModerator 2012年7月27日 17:27
全部回复
-
不晓得有没有弄错你的意思,有兴趣可以参考下列的T-SQL:
declare @t1 table (col1 int,col2 int) declare @t2 table (col3 int, col4 int) declare @t3 table (col5 int, col6 int) insert into @t1 values (1,33),(2,22),(3,11) insert into @t2 values (100,1),(200,2),(300,3) insert into @t3 values (1000,100),(2000,200),(3000,300) select * from ( select ROW_NUMBER() OVER (ORDER BY col2) as rownum,* from @t1 a inner join @t2 b on a.col1 = b.col4 inner join @t3 c on b.col3 = c.col6 ) t where rownum between 2 and 3
如果你是SQL SERVER 2012 可以用Order By 子句的新功能来做分页,像是下列的链接:
http://www.dotblogs.com.tw/terrychuang/archive/2012/06/25/73036.aspx
以上說明若有錯誤請指教,謝謝。
http://www.dotblogs.com.tw/terrychuang/- 已标记为答案 Tony xiaoModerator 2012年7月27日 17:27