讨论Oracle 中sql语句的执行顺序

查询语句的执行顺序:
select ename as name from scott.emp emp where emp.job=' CLERK' order by name;
select deptno,avg(sal),count() from scott.emp group by deptno order by count() desc;
select job,avg(sal) from scott.emp group by job having avg(sal)>2000;

1、先执行from       确定数据来自哪里
2、再执行where 条件   判断符合条件的数据,可以使用表scoot.emp 的别名emp
3、再执行group by 分组(筛选出行再分组)
4、having 分组过滤  (having必须跟group by 一起出现,没有group by 不能有having,where条件不能出现统计函数分组函数)
5、执行select 查询       查询数据
6、最后执行 order by     对查出来的数据排序,所以order by后可以使用字段eame的别名name