select * from tableB
where filed1 in (select case when A.filed2=0 then 'public'
when (select count(*) from tableA A, tableB where A.filed3 ='参数值'
and A.filed4=tableB.field4 and C.filed5=A.field5) =0 then 'publicaa'
when (select count(*) from tableA A, tableB where A.filed3 ='参数值'
and A.filed4=tableB.field4 and C.filed5=A.field5) >0 then '参数值' end
from tablbC C
where a0orgn.orgnno ='参数值'
)
order by fieldOrder
另外,case中也可以包含多个过滤条件,比如case when field1=‘aa’ and field2='bb' then 'xx'等
本文介绍了一个复杂的SQL查询案例,包括使用in子句与嵌套的case表达式进行数据筛选的方法。案例展示了如何根据不同条件返回特定字符串,并通过子查询增强查询的灵活性。

被折叠的 条评论
为什么被折叠?



