判断某列字段值是否都相同

若b列的值都为1则返回Y,否则返回X

declare @t table(a int,b int)
insert @t
select 1,1 union all 
select 2,1 union all 
select 3,1 union all 
select 4,0 

select b=case when exists(select b from @t where b<>1then 'X' else 'Y' end 
 
result:   b
        -------
            X
原文地址:https://www.cnblogs.com/perfect/p/555123.html