解析關于SQL語句Count的一點細節建站知識
導讀:1建站知識本篇文章是對關于SQL語句Count的一點細節進行了詳細的分析介紹,需要的朋友參考下seo網站關鍵詞優化網站建設公司。
count語句支持*、列名、常量、變量,并且可以用distinct關鍵字修飾, 并且count(列名)不會累計null的記錄。下面隨便用一些例子示范一下count的規則:比如對如下表做統計,所有列這里都用sql_variant類型來表示。
復制代碼 代碼如下:
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 網站seo優化課程go select count (* ) --總數 , count (null網站優化seo培訓if (1 , 1 )) --永遠返回0 , 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 (38 ))), 0 ))--a是數字的數量 from t_test
相關seo網站關鍵詞優化網站建設公司。聲明: 本文由我的SEOUC技術文章主頁發布于:2023-05-23 ,文章解析關于SQL語句Count的一點細節建站知識主要講述語句,細節,SQL網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.comhttp://www.xahuichuang.com