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子句后边使用 用户变量