我目前有两个单独的查询:
1) 根据各种过滤器返回实际结果集。
select a, b, c from TableA
where x = 123
and y = 'ABC'
and z = 999
2) 显示总行数。
select count(*) from TableA
where x = 123
and y = 'ABC'
and z = 999
所以简而言之,我运行相同的查询两次。我上面作为示例的查询比我使用多个联接和许多过滤器的查询要简单得多。
是否有更好的方法来实现相同的目标?
最佳答案
select a, b, c, count(*) over() as total
from dbo.TableA
where x = 123
and y = 'ABC'
and z = 999;
关于sql-server - 计算行数而不发出单独的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19937596/