oracle里面有emp表么,Oracle自带表(EMP)SQL语句练习
解法一: select ename from (select ename from emp order by sal desc) where rownum=1;
解法二: select ename from emp where sal=(select max(sal) from emp);
解法三: select ename, sal from emp where sal not in (select distinct t1.sal from emp t1 inner join emp t2 on t1.sal < t2.sal);
1. 計算每位員工的年薪
select ename, sal*12+nvl(comm, 0) annualSalary from emp;
2. 統計有員工的部門的人數
select count(distinct deptno) from emp;
3. 求掙最高薪水的員工(boss除外)的姓名
select ename from emp where sal = (select max(sal) from emp where job<>upper('president'));
4. 查詢薪水超過平均薪水的員工的姓名和工資
select ename, sal from emp where sal > (select avg(sal) from emp);
5. 查詢薪水超過其所在部門平均薪水的員工的姓名、部門編號和工資
select ename, t1.deptno, to_char(sal, '$9,999.9') sal, to_char(round(t2.avgsal, 1), '$9,999.9') avg from emp t1,(select deptno, avg(sal)
avgsal from emp group by deptno) t2 where t1.sal > t2.avgsal and t1.deptno = t2.deptno;
6. 查詢部門中薪水最高的人姓名、工資和所在部門名稱
select ename, sal, dname from emp t1
inner join
(select deptno, max(sal) maxsal from emp group by deptno) t2
on t1.deptno = t2.deptno and t1.sal = t2.maxsal
inner join
dept t3 on t3.deptno = t1.deptno;
7. 查詢部門平均薪水的等級
select deptno, avg, grade from (select deptno, avg(sal) avg from emp group by deptno) t1 inner join salgrade t2 on t1.avg between
t2.losal and t2.hisal;
8. 哪些人是主管
select ename from emp
where empno in (select distinct mgr from emp);
9. 求平均薪水最高的部門的名稱和平均工資
select dname, to_char(avg, '$9,999.9') avg from dept t1
inner join (select deptno, avg from (select deptno, avg(sal) avg from emp group by deptno) where avg = (select max(avg) from (select deptno, avg(sal) avg from emp group by deptno))) t2 on t1.deptno = t2.deptno;
10. 求薪水最高的前3名雇員
select * from (select ename, sal from emp order by sal desc) t where rownum <= 3;
11. 求薪水最高的第4-6名雇員
select ename, sal from (select rownum as rn, t.* from (select ename, sal from emp order by sal desc) t) where rn >= 4 and rn <= 6;
12. 求薪水最低的部門經理所在部門的名稱
總結
以上是生活随笔為你收集整理的oracle里面有emp表么,Oracle自带表(EMP)SQL语句练习的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: plsql oracle服务端,PLSQ
- 下一篇: oracle nvachar 长度,Or