如何使用TOP * select返回总记录数 [英] How to return total number of records with TOP * select

查看:293
本文介绍了如何使用TOP * select返回总记录数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有超过300 000行,我想返回总记录数,即使我只使用TOP *语句选择20/50/100记录。

I have over 300 000 rows, I would like to return total number of the records even if I pick only 20/50/100 records using TOP * statement.

是否可以筛选类似

select top 50 * from table where rule1 = rule1 and rule = rule2

假设数据库的总记录数为300 000,选择上面的记录将返回4 000条记录。但实际上它将只返回50条记录,我需要知道数据库中是如何使用其中语句(它将返回4000)。

Let's say that total number of records if database is 300 000 and select above would return 4 000 records. But physically it will return only 50 records, I need to know how manu is there in database using this where statement (it would return 4000).

感谢

推荐答案

这个问题有很多简单的答案,出来。根据你的情况,还有很多细微之处。有关此问题的深入讨论@ 使用row_number从查询中获取@@ rowcount的高效方法

There are a lot of simple answers to this question, as other posters have pointed out. There is also a lot of subtlety depending on your scenario. There is a fairly in depth discussion of the issue @ Efficient way of getting @@rowcount from a query using row_number

这篇关于如何使用TOP * select返回总记录数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆