select e.deptno, avg(e.sal)
from emp e
where avg(e.sal)>2000
group by e.deptno;select e.job,sum(e.sal) salsum
from emp e
where e.job!='SALESMAN'
group by e.job
order by salsum asc;
不是说 分组函数只能在分组函数中使,不能在 where语句中实现
第一个不能再 mysql 中实现 为什么第二个却可以实现
select e.deptno, avg(e.sal)
from emp e
where avg(e.sal)>2000
group by e.deptno;
select e.job,sum(e.sal) salsum
from emp e
where e.job!='SALESMAN'
group by e.job
order by salsum asc;
不是说 分组函数只能在分组函数中使,不能在 where语句中实现
第一个不能再 mysql 中实现 为什么第二个却可以实现
一般运行顺序:
from
where
group by having
select
order by
因此order by可以使用select中的别名