数据库SQL之and、or优先级

数据库SQL之and、or优先级

操作表:表TABLE_A、表TABLE_B

条件:获取当前用户是主持人、或是记录人、或是创建人、或子表中类型为01,02,并且为当前用户id的数据。

SELECT *
FROM TABLE_A A,TABLE_B B 
WHERE A.STATUS = '200' AND
	  A.ZCR = '用户id'  OR 
	  A.JLR='用户id' OR 
	  A.CREATE_BY = '用户id' OR
	  A.ID = B.CID  AND  B.TYPE IN ('01','02') AND   B.USER_ID = '用户id'

考虑and 、or的优先级之后的写法(仅供参考)

SELECT *
FROM TABLE_A A
LEFT JOIN TABLE_B B 
ON A.ID = B.CID AND 
B.TYPE IN ('01','02') AND B.USER_ID='用户id'
WHERE A.STATUS = '200'  AND 
(A.ZCR='用户id' OR A.JLR = '用户id' OR A.CREATE_BY = '用户id')

结论:and优先级高于or的优先级;

优先级排序:not 优先级高于 ; and 优先级高于 or

你可能感兴趣的:(Oracle)