首页 新闻 赞助 找找看

ORACLE的where怎么让其中一个条件随另外一个字段的值变化而变化

0
悬赏园豆:10 [已解决问题] 解决于 2017-09-28 17:01

比如:

select * from user_table u,org_code o where o.msg_status ='' and u.status in('6','7');

如果o.msg_status ='0' 那么u.status in('6','7');

如果o.msg_status ='1' 那么u.status in('1','2');

 

这个怎么在一条sql里面表现出来???

luoshifu的主页 luoshifu | 初学一级 | 园豆:80
提问于:2017-09-11 11:00
< >
分享
最佳答案
0

select * from user_table u,org_code o where u.status in(case o.msg_status when '0'  then '6,7' when '1' then '1,2' end)

收获园豆:10
LLSmile | 菜鸟二级 |园豆:257 | 2017-09-14 13:32
其他回答(3)
0

select * from user_table u,org_code o where o.msg_status ='0'  and u.status in('6','7')

union

select * from user_table u,org_code o where o.msg_status ='1'  and u.status in('1','2')

吴瑞祥 | 园豆:29449 (高人七级) | 2017-09-11 11:08

其实我的sql没有这么简单的,用union就非常长了,就是不想用union,有没别的方法?

支持(0) 反对(0) luoshifu | 园豆:80 (初学一级) | 2017-09-11 11:15

@luoshifu: 本质上.你这就是一个或查询.

不想连接就or一下

支持(0) 反对(0) 吴瑞祥 | 园豆:29449 (高人七级) | 2017-09-11 11:17
0

触发器.....

姚刘乐 | 园豆:70 (初学一级) | 2017-09-11 13:39
0

如果... 那么... 这不就是标准的case when then 语句吗?

Sirius02 | 园豆:204 (菜鸟二级) | 2017-09-29 17:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册