And OR IN 之间的关系和区别?

And  OR  IN  之间的关系和区别?

1)and的优先级>or

      Eg: 1 and 2 or 1 and 3 等价于  (1 and 2) or (1 and 3)

2)In 等价于(几个or 一起使用)

     Eg: in (A,B,C)    等价于   or A or B or C

3)In的性能比or好,In判断一次,or可能判断多次。

描述:

短信表:(d_remind_processed_order_mb)

ACTION_ID : 活动id

STATE :活动状态。

(1)

select count(1) from d_remind_processed_order_mb t 
where t.ACTION_id = 139966 and (T.STATE = 'POD' OR T.STATE = 'POP') ; 

 

 (2)

select count(1) from d_remind_processed_order_mb t 
where t.ACTION_id = 139966 and t.state in ('P0D','P0P');

(3)

select count(1) from d_remind_processed_order_mb t 
where (t.state = 'P0D' or t.state = 'P0P') and t.action_id = 139966;

 

(4) 

select count(1) from d_remind_processed_order_mb t 
where t.ACTION_ID = 139966 AND T.STATE = 'P0D'
OR T.ACTION_ID = 139966 AND T.STATE = 'P0P';

 

不解问题:
为什么(1)和(3)的查询结果是不一样的,他们只是调换了位置,括号也是打上的?

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值