一个比较复杂的sql

来源:互联网 发布:湖南飘香食品淘宝 编辑:程序博客网 时间:2024/06/05 04:53

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'等

原创粉丝点击