MySQL运算符的优先级

时间:2022-04-08 17:24:35

scenese:在写SQL语句时,组装WHERE条件时,曾出现过因AND,OR优先级问题导致的语句运行结果错误的BUG,故写下此BUG,引以为戒。

转载于:MySQL运算符的优先级 http://www.cnblogs.com/helingfeng/p/6486854.html

优先级 运算符
(最高)  !
    -(负号),~(按位取反)
    ^(按位异或)
    *,/(DIV),%(MOD)
    +,-
    >>,<<
    &
    |
    =(比较运算),<=>,<,<=,>,>=,!=,<>,IN,IS NULL,LIKE,REGEXP
   BETWEEN AND,CASE,WHEN,THEN,ELSE
   NOT
   &&,AND
   XOR
   ||,OR
(最低)    =(赋值运算),:=