时间:2021-07-01 10:21:17 帮助过:16人阅读
ROWNUM EMPNO ENAME SAL
------- ---------- ---------- ----------
1 7839 KING 5000
2 7788 SCOTT 3000
3 7902 FORD 3000
4.使用rownum进行分页
--解题思路:r 为e1的行号,为 e2的列,因为不是e2的行号,所以可以>=5 select e2.* from (select rownum r,e1.* from(select * from emp order by sal) e1 where rownum<=8 ) e2 where r>=5;
5.找到员工表中薪水大于本部门平均薪水的员工
--子查询 select e.empno,e.ename,e.sal,d.avgsal from emp e,(select deptno,avg(sal) avgsal from emp group by deptno) d where e.deptno=d.deptno and e.sal>d.avgsal;
--解题思路:相关子查询 select empno,ename,sal,(select avg(sal) from emp where deptno=e.deptno) avgsal from emp e where sal>(select avg(sal) from emp where deptno=e.deptno);
5.统计每年入职的员工个数
--使用case when then select count(*) Total, sum(case to_char(hiredate,‘yyyy‘) when ‘1981‘ then 1 else 0 end) from emp; --使用decode select count(*) Total, sum(decode(to_char(hiredate,‘yyyy‘),‘1981‘,1,0)) "1981" from emp;
SQL语句练习
标签:decode case rac ack 参数 font creat 分页 create