sql语句 查询记录数

需要查询数据表,top 50 某一字段为空的数量.
我尝试使用select top 50 count(*) from table where 字段=''.结果发现.top 50并未生效.
求有效方法
哦.补充下..是mssql2000里的问题..

wohenhao正解我的意思..感觉,不过 语句中的a是什么意思?居然换成b也没错

sql中查询记录数用count函数。

1、创建测试表,插入数据:

create table test
(id int)

insert into test values (1)
insert into test values (2)
insert into test values (3)
insert into test values (null)

2、查询记录数为两种,一种是count(*),一种是count(字段值):

测试一:

select count(*) from test

结果:

测试二:

select count(id) from test

结果:

说明:如果count(字段名)的字段中含有空值,则在count中不计数,而count(*)则是查询全部的行数。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-11-27
top 50是查询前面50个记录,而不是查询数量
select top 50 * from table where 字段 is null
第2个回答  2009-11-27
DECLARE @n INT
SET @n = 500
SET ROWCOUNT @n
SELECT * FROM Table_name
这样,查询结果将等同于

SELECT TOP 50 FROM Table_name
第3个回答  2009-11-27
select count(*) from (select top 50 * from table) a where 字段=''本回答被提问者采纳
相似回答