注册 登录
编程论坛 MySQL论坛

关于字段别名的问题

davidfang93 发布于 2020-11-10 15:15, 3359 次点击
为啥将select后的字段起上别名后,HAVING中即能直接使用字段,也能使用别名,而where后面就不行呢?
例:SELECT AVG(salary) a,department_id
    FROM employees
    GROUP BY department_id
    HAVING AVG(salary)>1000;

SELECT AVG(salary) a,department_id
    FROM employees
    GROUP BY department_id
    HAVING a>1000;
两者都行

SELECT employee_id i,salary FROM employees
WHERE i>10;
这样的就不行
0 回复
1