なぜwhere文で集約関数を使用できないのか


1.問題の説明
select deptno ,avg(sal) from emp where count(*)>3 group by deptno; where文で集約関数count(*)を使用してエラーを報告します:ORA-00934:group function is not allowed here
それはなぜですか.
2.問題解決:
sql文の実行手順は、from-->where-->group by-->having-->order by-->selectである.
集約関数は結果セットに対して行われますが、where条件は結果セットがクエリーされた後に実行されるわけではありませんので、メイン関数をwhere文に置くとエラーが発生します.
havingは異なり、havingは結果セットをフィルタリングするので、私のドアは一般的にhavingの中に置いて、havingでwhereの代わりにして、havingは一般的にgroupbyの後についています.
コード:
select deptno,avg(sal) from emp group by deptno having count(deptno)>3;