3 ms·
should return an error, the select part is read last by the DB, so whatever you define in the select part (employees_no) is not available to the having clause.
by cm2187 5y ago
should return an error, the select part is read last by the DB, so whatever you define in the select part (employees_no) is not available to the having clause.
SELECT department_id, count(*) AS employees_no FROM employee WHERE gender = 'F' GROUP BY department_id HAVING count(*) < 10;
The logical order in which the DB processes the query is:
FROM Employee
WHERE gender = 'F'
GROUP BY department_id
HAVING count(*) < 10
SELECT department_id, count(*) as employees_no
so you apply count(*) < 10 after you filtered by gender and after you grouped by department_id
- magicalhippo 5y ago> should return an error Except some databases allow for that syntax. The one we use, SQLAnywhere, does.
- totoglazer 5y agoDepends on the db. Plenty make such aliases available for having & order by.
- deleted 5y ago[deleted]