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)的查询结果是不一样的,他们只是调换了位置,括号也是打上的?