--> 测试数据:[tb] if object_id('[tb]') is not null drop table [tb] go create table [tb]([a] int,[b] int,[c] varchar(1),[列名] sql_variant) insert [tb] select 1,2,'t',null union all select 2,3,'t',null union all select 4,3,'r',null union all select 4,5,'r',null union all select 1,2,'w',null--------------------------------查询开始------------------------------select count(distinct c) from [tb] /*----------- 3(1 行受影响)*/
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([a] int,[b] int,[c] varchar(1),[列名] sql_variant)
insert [tb]
select 1,2,'t',null union all
select 2,3,'t',null union all
select 4,3,'r',null union all
select 4,5,'r',null union all
select 1,2,'w',null--------------------------------查询开始------------------------------select count(distinct c) from [tb]
/*-----------
3(1 行受影响)*/
count(distinct c) as cnt
from tb