--數(shù)據(jù)分組-max,min,avg,sum,count --如何顯示所有員工中最高工資和最低工資 select min(sal) from emp --能查詢出最低工資 --如何顯示最低工資和該雇員的名字 select ename,sal from emp where sal=(select min(sal) from emp) --可以實現(xiàn) --顯示所有員工的平均工資和工資總和 select avg(sal) '平均工資',sum(sal) 總工資 from emp --把高于平均工資的雇員的名字和他的工資顯示 select ename,sal from emp where sal>(select avg(sal) from emp) --把高于平均工資的雇員的名字和他的工資顯示,并顯示平均工資 select ename,sal,(select avg(sal) from emp) from emp where sal>(select avg(sal) from emp) 這個效率不高,以后可以改進 --計算共有多少員工 select count(*) from emp ---group by 和 having字句 --請問如何顯示每個部門的平均工資和最高工資 select avg(sal), depno, max(sal) from emp group by depno --顯示每個部門的每種崗位的平均工資和最低工資 select avg(sal),min(sal),deptno,job from emp group by deptno,job order by deptno --顯示平均工資低于2000的部門號和它的平均工資 --having 往往和group by 結(jié)合使用,可以對分組查詢結(jié)果進行篩選 select avg(sal),depyno from emp group by deptno having avg(sal)<2000 |
|
來自: jtll521 > 《spl server學習》