很久没有去深究运算符的优先级了,今天写SQL解析思考了一下。
下面这条SQL真正的执行顺序是什么?
select * from taobao_category where type=1 or id=801 and type=3 and type=4
改成python脚本:
def test(type,id): print type==1 or id==801 and id==802 and id==803
测试结果是True
基本所有的语言的优先级都是 not>and>or,
所以上面那段python表达式实际是: (type==1) or (id==801 and id==802 and id==803),sql也就是:
select * from taobao_category where (type=1) or (id=801 and type=3 and type=4)
mysql> select * from taobao_category where type=0 and type=1 or id=324 and id =23 or id=830; +-----+----------+------+-----------+-----------------+------+------+--------+ | id | cid | type | parent_id | name | url | des | status | +-----+----------+------+-----------+-----------------+------+------+--------+ | 830 | 50024129 | 0 | 1402 | - | NULL | NULL | NULL | +-----+----------+------+-----------+-----------------+------+------+--------+ 1 row in set (0.00 sec)
相关推荐
C语言各运算符优先级及函数大全、ASCII码表、C语言的格式输入输出
夏宇闻 verilog 书中讲的运算符优先级不全,这里给出了较全的版本。
C#运算符优先级解释
C语言运算符优先级
C++ 运算符优先级列表,非常详细的运算符优先级的总结!
C语言运算符优先级
非常详细的java运算符优先级表,帮助记住优先级顺序
C++运算符优先级表,可供下载下载打印,十分方便
C语言运算符优先级,同一优先级的运算符,运算次序由结合方向所决定。简单记就是:! > 算术运算符 > 关系运算符 > && > || > 赋值运算符
C语言运算符优先级和结合性表,全面介绍了C语言运算符的优先级和结合性。
C语言运算符优先级的详细列表,附特殊符号(转行、回车)的表达。
C运算符优先级PDF C运算符优先级PDF C运算符优先级PDF
C语言运算符优先级和口诀 便于在学习C语言中查阅哦。
关于C++运算符优先级的总结,为了找工作面试的时候用。
C语言运算符优先级C语言运算符优先级
运算符优先级图表
介绍了C/C++ 中所有运算符的优先级顺序
全面的 PASCAL运算符优先级, PASCAL运算符优先级.doc 。
js开发运算符优先级列表,需要的可以看一下,运算符优先级.pdf