SQL语句AND 和 OR执行的优先级

时间:2022-02-03 17:01:52

例句:

SELECT COUNT(1) FROM RT_CUSTALLOCRESULT
WHERE REGDATE BETWEEN '2014-03-01' AND '2014-03-31'
OR (DATE(NEXTTRACKDATE) BETWEEN '2014-03-01' AND '2014-03-31') AND SALEID = 2003

SQL语句AND 和 OR执行的优先级

SELECT COUNT(1) FROM RT_CUSTALLOCRESULT
WHERE (REGDATE BETWEEN '2014-03-01' AND '2014-03-31'
OR (DATE(NEXTTRACKDATE) BETWEEN '2014-03-01' AND '2014-03-31')) AND SALEID = 2003

SQL语句AND 和 OR执行的优先级

没带括号前,优先执行

(DATE(NEXTTRACKDATE) BETWEEN '2014-03-01' AND '2014-03-31') AND SALEID = 2003 
带了括号后,优先执行
(REGDATE BETWEEN '2014-03-01' AND '2014-03-31'
OR (DATE(NEXTTRACKDATE) BETWEEN '2014-03-01' AND '2014-03-31'))