小编Rob*_*elo的帖子

SQL Server,为多个表使用UNION ALL然后分页实现

我还需要有关分页和使用UNION ALL多个表的帮助:

如何在使用UNION ALL并返回特定行数时连接多个表时实现优化的分页...


declare @startRow int
declare @PageCount int

set @startRow = 0
set @PageCount = 20

set rowcount @PageCount

select Row_Number() OVER(Order by col1) as RowNumber, col1, col2
from
(
    select col1, col2 from table1 where datetimeCol between (@dateFrom and @dateTo)
    union all
    select col1, col2 from table2 where datetimeCol between (@dateFrom and @dateTo)
    union all
    select col1, col2 from table3 where datetimeCol between (@dateFrom and @dateTo)
    union all
    select col1, col2 from table4 …
Run Code Online (Sandbox Code Playgroud)

sql-server pagination union-all

12
推荐指数
1
解决办法
2万
查看次数

标签 统计

pagination ×1

sql-server ×1

union-all ×1