22,209
社区成员
发帖
与我相关
我的任务
分享
with t1(s) as
(
--select 'A' UNION ALL --注释切换
--select 'B' UNION ALL
--select 'A'
select 'A' UNION ALL
select 'A' UNION ALL
select 'A'
)
SELECT MAX(s) AS s
FROM t1
HAVING COUNT(DISTINCT s) = 1
UNION ALL
SELECT s
FROM t1 a
WHERE EXISTS(SELECT * FROM t1 WHERE s <> a.s)
with t1(s) as
(
--select 'A' UNION ALL --注释切换
--select 'B' UNION ALL
--select 'A'
select 'A' UNION ALL
select 'A' UNION ALL
select 'A'
)
select t1.*
from t1
,(select 1 cc from (select case when COUNT(distinct s)=1 then 1 else 0 end c from t1) t where t.c!=1)tt
union all
select distinct t1.*
from t1
,(select 1 cc from (select case when COUNT(distinct s)=1 then 1 else 0 end c from t1) t where t.c=1)tt