select a,count(1) from (select a,1 union all select a,2 union all select a,3 union all select a,4 union all select a,5 union all select a,6 union all) k group by a having count(1)>3
动态 declare @sql varchar(1000) set @sql='' select @sql=@sql+ ' select a,'+[name]+' as countc from tablename union all' from syscolumns where object_id('tablename')=id set @sql=left(@sql,len(@sql)-10) set @sql='select a,count(countc) from ('+@sql+') k group by a having count(countc)>3' print @sql
select a, tORf=(case when charindex('ttt',replace([1]+[2]+[3]+[4]+[5]+[6],'f',''),1)>0 then 'T' else 'F' end) from tb
select a, tORf=(case when len(replace([1]+[2]+[3]+[4]+[5]+[6],'f','')>=3 then 'T' else 'F' end) from tb
union all
select a,2
union all
select a,3
union all
select a,4
union all
select a,5
union all
select a,6
union all) k group by a having count(1)>3
set @sql=''
select @sql=@sql+ ' select a,'+[name]+' as countc from tablename union all'
from syscolumns where object_id('tablename')=id
set @sql=left(@sql,len(@sql)-10)
set @sql='select a,count(countc) from ('+@sql+') k group by a having count(countc)>3' print @sql
from tb
from tb