溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

SQL語(yǔ)句Count的細(xì)節(jié)是什么

發(fā)布時(shí)間:2021-12-01 11:35:23 來(lái)源:億速云 閱讀:115 作者:柒染 欄目:數(shù)據(jù)庫(kù)

本篇文章為大家展示了SQL語(yǔ)句Count的細(xì)節(jié)是什么,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。

count語(yǔ)句支持*、列名、常量、變量,并且可以用distinct關(guān)鍵字修飾, 并且count(列名)不會(huì)累計(jì)null的記錄。下面隨便用一些例子示范一下count的規(guī)則:

比如對(duì)如下表做統(tǒng)計(jì),所有列這里都用sql_variant類(lèi)型來(lái)表示。

代碼如下: 

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

上述內(nèi)容就是SQL語(yǔ)句Count的細(xì)節(jié)是什么,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI