- 我的电脑系统:Windows 10 64位
- SQL Server 软件版本: SQL Server 2014 Express
SQL Server 查询语句的顺序
select top ...
from A
join B
on ...
join C
on ...
where ...
group by ...
having ...
order by ...
例子
本例子里面使用了库,如何你现在还没有添加这个库到你的服务器里面,请在查看本篇博客前,访问这篇博文来在你的服务器里面附加
scott
库。
scott
求出平均薪水最好的部门的标号和部门的平均工资
--求出平均薪水最好的部门的标号和部门的平均工资
--第1种写法:
select top deptno, avg(sal) "avg_sal"
from emp "E"
group by deptno
order by avg(sal) desc
等价于:
--求出平均薪水最好的部门的标号和部门的平均工资
--第2种写法:
select "E".*
from (
select deptno, avg(sal) "avg_sal"
from emp
group by deptno
) "E"
where "E"."avg_sal" = (
select max("avg_sal")
from (
select deptno, avg(sal) "avg_sal"
from emp
group by deptno
) "T"
)
请访问:http://www.aobosir.com/