关键字执行顺序之select-having疑问
网上查询出来的关键字执行顺序都是FROM、ON 、JOIN、WHERE、GROUP BY、AGG_FUNC、WITH、HAVING、SELECTHAVING 再SELECT前
SELECT AVG(salary)avg_sal,d.*
FROM employees e
JOIN departments d
ON e.department_id=d.department_id
GROUP BY department_id
HAVING avg_sal=(
SELECT MIN(avg_sal.avg)
FROM (
SELECT AVG(salary) avg
FROM employees
GROUP BY department_id
) avg_sal
);
这段SQL 并没有报错 HAVING后的avg_sal是SELECT中取得别名。
按网上说的顺序,这里avg_sal应该找不到。
有没有大佬讲解讲解。