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 

 

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 

 

没带括号前,优先执行

(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'))


posted @ 2014-03-20 20:34  沙耶  阅读(8786)  评论(0编辑  收藏  举报