mysql語句的執行順序問題
是select 先執行還是group by 先執行?
是select 先執行 還是 having 子句先執行??
mysql> select (@a :=empid) a ,heyf_t10.* from heyf_t10 ;
www.2cto.com
+---+-------+--------+--------+
| 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 的時候 結果集為什麼是空的呢??
www.2cto.com
---------------------------------------------------------------
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子句後邊使用 用戶變量