The count Statement supports *, column name, constant, and variable, and can be modified with the distinct keyword, and count (column name) does not accumulate null records. Here are some examples to demonstrate the count rule: for example, to make statistics for the following table, all columns are represented by the SQL _variant type.
Copy codeThe Code is as follows:
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 (*) -- total
, Count (nullif (1, 1) -- returns 0 forever
, Count (a) -- a quantity
, Count (B) -- number of B
, Count (distinct a) -- a does not repeat the number
, Count (isnull (B, c) -- the number of B or c values not null
, Count (Coalesce (a, B, c) -- the number of a, B, or c is not null.
, Count (nullif (a, B) -- a is not equal to the number of B
, Count (nullif (isnumeric (cast (a as varchar (38), 0) -- a is the number of digits.
From t_test