先看例子
mysql> SELECT id,b AS B1 from test where B1 > 2;
ERROR 1054 (42S22): Unknown column 'B1' in 'where clause'
mysql> SELECT * from (SELECT id,b AS B1 from test) u where B1>2;
+----+------+
| id | B1 |
+----+------+
| 1 | 4 |
| 3 | 5 |
| 5 | 4 |
| 6 | 3 |
+----+------+
MySQL 别名查询不能用于当前条件子句中查询的原因是MySQL查询语句执行顺序;
from join on where group by [sum,avg] having select distict order by limit
所以只能用派生表(derived table)
待写:
group by having 中可以用别名

177

被折叠的 条评论
为什么被折叠?



