emp单表select练习

来源:互联网 发布:nc57数据库系统是什么 编辑:程序博客网 时间:2024/05/08 19:04
--求出每个部门工资总和  每个岗位工资总和  每个雇员总工资
select e.deptno||'',sum(e.sal) from emp e group by e.deptno
union all
select e.job||'',sum(e.sal) from emp e group by e.job
union all
select '',sum(e.sal) from emp e;

--求出每个部门工资总和  每个岗位工资总和  每个雇员总工资
select e.deptno 部门,e.job 岗位,sum(e.sal) 工资总和 from emp e group by grouping sets(e.deptno,e.job,null);
--用分页求出工资排位在6——10之间的员工包括6、10
select * from (select a.*,rownum r from (select * from emp e order by e.sal desc) a where rownum<=10) b where b.r>=6;
--最高工资
select max(sal) from emp;
--最低工资  并列出这个最高工资的人物信息
select * from emp where sal =(select min(sal) from emp) ;
--平均工资
select avg(sal) from emp;

--求出一共有多少个部门重复的不算  不要求列出具体内容  求出一个数据就行
select count(distinct e.deptno) 部门总数 from emp e;
--求出每个部门的平均工资
select e.deptno,to_char(avg(e.sal),'9999.99') from emp e group by e.deptno;
--求出最高工资的员工姓名
select * from emp where sal=(select max(sal) from emp);
--每一个部门里工资最高的人  (拓展最好能把姓名也展示出来)
select * from emp where sal in (select max(sal) from emp group by deptno)
0 0
原创粉丝点击