您好,欢迎来到刀刀网。
搜索
您的当前位置:首页mysql语句的执行顺序问题_MySQL

mysql语句的执行顺序问题_MySQL

来源:刀刀网


bitsCN.com
mysql语句的执行顺序问题 是select 先执行还是group by 先执行?是select 先执行 还是 having 子句先执行?? mysql> select (@a :=empid) a ,heyf_t10.* from heyf_t10 ; +---+-------+--------+--------+ | a | empid | deptid | salary | +---+-------+--------+--------+ | 1 | 1 | 10 | 5500 | | 2 | 2 | 10 | 4500 | | 3 | 3 | 20 | 1900 | | 4 | 4 | 20 | 4800 | | 5 | 5 | 40 | 6500 | | 6 | 6 | 40 | 14500 | | 7 | 7 | 40 | 44500 | | 8 | 8 | 50 | 6500 | | 9 | 9 | 50 | 7500 | +---+-------+--------+--------+ 9 rows in set mysql> select (@a :=empid) a ,heyf_t10.* from heyf_t10 having @a =5; Empty set 第二个查询 条件是 having @a=5 的时候 结果集为什么是空的呢?? --------------------------------------------------------------- mysql> select (@a :=empid) a ,heyf_t10.* from heyf_t10 having empid =5; +---+-------+--------+--------+ | a | empid | deptid | salary | +---+-------+--------+--------+ | 5 | 5 | 40 | 6500 | +---+-------+--------+--------+ 1 row in set 为什么 当条件 使用having empid=5 的时候能够正常返回数据记录 总结 不能在group by, having,ORDER BY子句后边使用 用户变量 bitsCN.com

Copyright © 2019- gamedaodao.com 版权所有 湘ICP备2022005869号-6

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务