您可以尝试以下解决方案:
;with temp_data as (
select 1 as num1 , 1 as num2 , 1 as num3 , 2 as num4 , 3 as num5 , 4 as num6 union all
select 1 as num1 , 1 as num2 , 1 as num3 , 1 as num4 , 3 as num5 , 4 as num6 union all
select 2 as num1 , 2 as num2 , 2 as num3 , 3 as num4 , 2 as num5 , 6 as num6
)
SELECT *
FROM temp_data
where 3=(CASE WHEN num1=num2 THEN 1 ELSE 0 END)+
(CASE WHEN num1=num3 THEN 1 ELSE 0 END)+
(CASE WHEN num1=num4 THEN 1 ELSE 0 END)+
(CASE WHEN num1=num5 THEN 1 ELSE 0 END)+
(CASE WHEN num1=num6 THEN 1 ELSE 0 END)
OR
3=(CASE WHEN num2=num1 THEN 1 ELSE 0 END)+
(CASE WHEN num2=num3 THEN 1 ELSE 0 END)+
(CASE WHEN num2=num4 THEN 1 ELSE 0 END)+
(CASE WHEN num2=num5 THEN 1 ELSE 0 END)+
(CASE WHEN num2=num6 THEN 1 ELSE 0 END)
OR
3=(CASE WHEN num3=num1 THEN 1 ELSE 0 END)+
(CASE WHEN num3=num2 THEN 1 ELSE 0 END)+
(CASE WHEN num3=num4 THEN 1 ELSE 0 END)+
(CASE WHEN num3=num5 THEN 1 ELSE 0 END)+
(CASE WHEN num3=num6 THEN 1 ELSE 0 END)
OR
3=(CASE WHEN num4=num1 THEN 1 ELSE 0 END)+
(CASE WHEN num4=num3 THEN 1 ELSE 0 END)+
(CASE WHEN num4=num2 THEN 1 ELSE 0 END)+
(CASE WHEN num4=num5 THEN 1 ELSE 0 END)+
(CASE WHEN num4=num6 THEN 1 ELSE 0 END) OR
3=(CASE WHEN num5=num1 THEN 1 ELSE 0 END)+
(CASE WHEN num5=num2 THEN 1 ELSE 0 END)+
(CASE WHEN num5=num4 THEN 1 ELSE 0 END)+
(CASE WHEN num5=num3 THEN 1 ELSE 0 END)+
(CASE WHEN num5=num6 THEN 1 ELSE 0 END)
OR
3=(CASE WHEN num6=num1 THEN 1 ELSE 0 END)+
(CASE WHEN num6=num2 THEN 1 ELSE 0 END)+
(CASE WHEN num6=num4 THEN 1 ELSE 0 END)+
(CASE WHEN num6=num3 THEN 1 ELSE 0 END)+
(CASE WHEN num6=num5 THEN 1 ELSE 0 END)
;
输出:
num1 num2 num3 num4 num5 num6
1 1 1 1 3 4
2 2 2 3 2 6
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。