如何获取已执行的select语句中的总行数? [英] How to get total number of rows in a executed select statement?
问题描述
如何确定执行后获得了多少行?
How can I out how many rows I obtained after execution?
我的查询是:
SELECT a.Emp,b.orders
from table as a inner join table1 b
on a.ID = B.ID
如何查找上述联接中返回的行数?
How do I find the number of rows returned in the above join?
推荐答案
您必须在相同条件下使用SELECT COUNT(*) ...
,或者通过
You either have to use SELECT COUNT(*) ...
with the same condition or add a column with the row-count via ROW_NUMBER
function:
SELECT a.Emp,b.orders, RN = ROW_NUMBER () OVER (ORDER BY a.Emp,b.orders)
FROM table as a inner join table1 b on a.ID=B.ID
...或使用 @@ROWCOUNT
选择之后.
...or use @@ROWCOUNT
after the select.
代替ROW_NUMBER
会更容易使用COUNT(*) OVER ( Order By ...)
,其中每行包含相同的总数,而ROW_NUMBER
将返回一个序号,其中只有最后一条记录(根据ORDER BY
)具有总计数.
Instead of ROW_NUMBER
it's easier to use COUNT(*) OVER ( Order By ...)
where each row contains the same total-count whereas ROW_NUMBER
would return a sequential number where only the last record(acc. to the ORDER BY
) would have the total-count.
So what Aaron has already meantioned in his answer.
这篇关于如何获取已执行的select语句中的总行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!