Home > Database > Mysql Tutorial > mysql语句的执行顺序问题_MySQL

mysql语句的执行顺序问题_MySQL

WBOY
Release: 2016-06-01 13:40:33
Original
1125 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template