oracle经典20道笔试题
1.列出至少有一个员工的所有部门。
select no,e
from dept,emp
where no=no
2.列出薪金比“SMITH”多的所有员工。
select * from emp
where sal >(select sal from emp where ename=’SMITH’)
3.列出所有员工的姓名及其直接上级的姓名。
select e,e
from emp yg,emp sj
where =o
4.列出受雇日期早于其直接上级的所有员工。
select e,e
from emp yg join emp sj on =o
where date
5.列出部门名称和这些部门的`员工信息,同时列出那些没有员工的部门。
select no,e,o,e
from dept left join emp
on no=no
6.列出所有“CLERK”(办事员)的姓名及其部门名称。
select * from dept,emp
where no=no
and job=’CLERK’
7.列出最低薪金大于1500的各种工作。
select job from emp
group by job
having min(sal)>1500
8.列出在部门名称为“SALES”(销售部)工作的员工的姓名,假定不知道销售部的部门编号。
方法一:
select e
from dept,emp
where no=no
and dname=’SALES’
方法二:
select * from emp
where deptno=(select deptno from dept where dname=’SALES’)
9.列出薪金高于公司平均薪金的所有员工。
select * from emp
where sal> (select avg(sal) from emp)
对比:列出薪金高于本部门平均薪金的所有员工。
方法一:
select * from emp a
where >(select avg(sal) from emp b where no=no)
缺点:相关子查询,效率低。
方法二:
select empno,ename,sal from
emp a,(select avg(sal) avg_sal from emp b where no=no) b
where no=no
and >_sal
10.列出与“SCOTT”从事相同工作的所有员工。
select * from emp
where job=(select job from emp where ename=’SCOTT’)
11.列出薪金等于部门30中员工的薪金的所有员工的姓名和薪金。
select ename,sal from emp
where sal=any(select sal from emp where deptno=30 )
12.列出薪金高于在部门30工作的所有员工的薪金的员工姓名和薪金。
方法一:
select ename,sal from emp
where sal>all(select sal from emp where deptno=30 )
方法二:
select ename,sal from emp
where sal>(select max(sal) from emp where deptno=30 )
13.列出在每个部门工作的员工数量、平均工资和平均服务期限。
select deptno,avg(trunc((sysdate-hiredate)/365)) as year
from emp
group by deptno
–参考:截断,取整函数
select trunc(99.9) from dual;
返回
99
14.列出所有员工的姓名、部门名称和工资。
select e,e,
from dept d,emp e
where no=no
说明:每个字段都加表前缀,效率要高些
15.列出所有部门的详细信息和部门人数。
select no,e,count(*)
from dept,emp
where no=no
group by no,e
16.列出各种工作的最低工资。
select job,min(sal) from emp group by job
17.列出各个部门的MANAGER(经理)的最低薪金。
select deptno,min(sal) from emp where job=’MANAGER’ group by deptno
18.列出所有员工的年工资,按年薪从低到高排序。
select empno,ename,sal*12 as 年薪 from emp
order by sal
19. 求各种工作工资最低的员工。
方法一:
select * from emp a
where sal=(select min(sal) from emp b where =)
方法二:
select emp.*
from emp a,( select job,min(sal) min_sal from emp group by job) b
where = and =_sal
20. 列出各种工作工资前3名的员工
select * from (
select empno,ename,sal,job,
dense_rank() over(partition by job order by sal desc) as 名次
from emp ) a
where a.名次<=2
order by job;
说明:用到了Oracle强大的“分区排名技术”,其中“dense_rank()”是Oracle的解析函数。
-
2016考研新闻传播学复习考点:外国新闻传播史
以下是本站为大家整理好的有关考研的资料,希望对大家有所帮助,如有疑问请关注本站!一、古代新闻传播发展的三个里程碑及其意义:(一)语言的产生是传播史上第一个重要的里程碑。1、应付大自然的威胁能力增强和共同劳动2、人类思维能力加强3、加快了人们信息交流的传...
-
2016考研时间无法充值:8个问题要及时解决
考研成绩要想好,行为习惯少不了。观察这几年的考研成绩,我们会发现,一个考研成绩好的学生,他/她为考研所采取的行为和习惯是最终让他/她取得好成绩的重要因素。印度谚语说:播种一种行为,收获一种习惯;播种一种习惯,收获一种性格;播种一种性格,收获一种命运。既然选...
-
报考指南:选择目标院校应以适合为主
以执着的坚守和艰辛的付出来应对考研路上的挫折,既然选择了放足远方,便无悔风雨兼程。而毅力的大部分来自于目标,目标的形成又多来自自身的性格。好的开始就是成功的一半,对已考研人也是一样的,明确考研的目标,你才算是真正的踏上了考研路。其中目标院校和专业尤其重...
-
安徽师范大学2016年考研世界史真题
2017考研已经悄然到来了,考生们也在积极寻找考研真题了。下面是小编为大家整理收集的关于安徽师范大学2016年考研世界史真题的相关内容,欢迎大家的阅读。名词解释:乌鲁卡基那改革,梭伦改革,希罗多德,尼西亚会议,末日审判书,拿破仑法典,加富尔,全国工业复兴法史料分析题:(...