SQL语句,一共有5个变量,只要满足其中任意三个变量或以上的SQL语句怎么写?

2024-11-30 20:46:14
推荐回答(2个)
回答1:

select *
from table
where 1=1
and (
case when condition1(@arg1) is true then 1 else 0 end
+ case when condition2(@arg2) is true then 1 else 0 end
+ case when condition3(@arg3) is true then 1 else 0 end
+ case when condition4(@arg4) is true then 1 else 0 end
+ case when condition5(@arg5) is true then 1 else 0 end
) >= 3

回答2:

最简单的就是用使用and和or来完成