注册 登录
编程论坛 SQL Server论坛

[求助]SQL中count()如何使用啊

flmls 发布于 2007-03-01 16:50, 2819 次点击
在SQL中计算count 如何使用,请指教



count()后的“()”里的填的数据是什么概念?
5 回复
#2
reniking2007-03-01 17:26

计数的,比如select count(ID) from table where ID<>1 就是选出ID列不等于1的行数

#3
flmls2007-03-01 17:30
如果count(*)说明什么?
是不是说明所有的啊

比如select count(*) from table

[此贴子已经被作者于2007-3-1 17:32:16编辑过]

#4
棉花糖ONE2007-03-01 18:07

count(*) 选出数据表的行数,select count(ID) from table where ID<>1这样的话,如果id是null,也会忽略

#5
flmls2007-03-01 20:12
忽略是不是指,把count(ID)认为成count(*)
#6
棉花糖ONE2007-03-01 20:40

不是啊,count(*)选出的记录是大于或等于count(id),你去做个实验
create table shiyan(id int,name varchar(10))
insert into shiyan select 1,'a'
insert into shiyan(name) select 'b'
select count(*) from shiyan
select count(id) from shiyan
第一个返回的是2,第二个返回的是1,因为id有一行是null

1