关于AVG() group by , having, where 字句的使用
关于使用聚合Avg函数,Having / Where 字句的位置。
请问,为什么 1, 2 没问题; 3可以,4却不行呢?
1. select ID, AVG(Salary) from EMPLOYEE Group by ID Having ID in ('ID1', 'ID2') -- OK
2. select ID, AVG(Salary) from EMPLOYEE where ID in ('ID1', 'ID2') Group by ID -- OK
3. select ID, AVG(Salary) from EMPLOYEE Group by ID Having count(*)>=2 -- OK
4. select ID, AVG(Salary) from EMPLOYEE where count(*)>2 Group by ID -- Not OK