--如果FValue字段的值为NULL则在COUNT(DISTINCT FValue)语句中不会被统计上 --所以要先将NULL值转变为一个非NULL的特殊数值 --'*'为用户自己定义但不会在VALUE中出现的值 --以下我给出了两种写法,各有好处--1 select distinct A.Ftype,( select count(distinct isnull(B.FValue,'*')) from table5 B where A.Ftype = B.Ftype ) as ccount from table5 A --2 select Ftype,count(distinct isnull(FValue,'*')) from table5 group by Ftype
--如果FValue字段的值为NULL则在COUNT(DISTINCT FValue)语句中不会被统计上
--所以要先将NULL值转变为一个非NULL的特殊数值
--'*'为用户自己定义但不会在VALUE中出现的值
--以下我给出了两种写法,各有好处--1
select distinct A.Ftype,( select count(distinct isnull(B.FValue,'*')) from table5 B where A.Ftype = B.Ftype ) as ccount
from table5 A
--2
select Ftype,count(distinct isnull(FValue,'*'))
from table5
group by Ftype