解析關(guān)于SQL語(yǔ)句Count的一點(diǎn)細(xì)節(jié)
發(fā)布日期:2022-01-02 01:52 | 文章來(lái)源:gibhub

復(fù)制代碼 代碼如下:
if (object_id ('t_test' )> 0 )
drop table t_test
go
create table t_test (a sql_variant , b sql_variant , c sql_variant )
insert into t_test select 1 , 1 , 'a'
insert into t_test select 1 , getdate (), null
insert into t_test select 'a' , null , 1
insert into t_test select 3 , null , null
insert into t_test select null , null , null
go
select * from t_test
go
select
count (* ) --總數(shù)
, count (nullif (1 , 1 )) --永遠(yuǎn)返回0
, count (a ) --a數(shù)量
, count (b) --b數(shù)量
, count (distinct a ) --a不重復(fù)數(shù)量
, count (isnull (b, c )) --b或者c不為null數(shù)量
, count (Coalesce (a , b, c )) --a或者b或者c不為null數(shù)量
, count (nullif (a , b)) --a不等于b的數(shù)量
, count (nullif (isnumeric (cast (a as varchar (38 ))), 0 ))--a是數(shù)字的數(shù)量
from t_test
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
相關(guān)文章