count語句支持*列名常量變量並且可以用distinct關鍵字修飾 並且count(列名)不會累計null的記錄下面隨便用一些例子示范一下count的規則比如對如下表做統計所有列這裡都用sql_variant類型來表示
復制代碼 代碼如下:
if (object_id (
t_test
)>
)
drop table t_test
go
create table t_test (a sql_variant
b sql_variant
c sql_variant )
insert into t_test select
a
insert into t_test select
getdate ()
null
insert into t_test select
a
null
insert into t_test select
null
null
insert into t_test select null
null
null
go
select * from t_test
go
select
count (* )
總數
count (nullif (
))
永遠返回
count (a )
a數量
count (b)
b數量
count (distinct a )
a不重復數量
count (isnull (b
c ))
b或者c不為null數量
count (Coalesce (a
b
c ))
a或者b或者c不為null數量
count (nullif (a
b))
a不等於b的數量
count (nullif (isnumeric (cast (a as varchar (
)))
))
a是數字的數量
from t_test
From:http://tw.wingwit.com/Article/program/MySQL/201311/29545.html