--求部门的平均薪水的等级
select deptno,avg(grade) from
(select deptno,ename,grade from emp
join salgrade s on emp.sal between s.losal and s.hisal)
group by deptno;
DEPTNO AVG(GRADE)
30 2.5
20 2.8
10 3.66666667
--雇员中有哪些是经理人
select ename from emp where empno in(select mgr from emp);
或select ename from emp where empno in(select distinct mgr from emp);更有效
ENAME
FORD
BLAKE
KING
JONES
SCOTT
CLARK
--不准用组函数,求薪水最高值
select distinct sal from emp where sal not in
(
select distinct e1.sal from emp e1
join emp e2 on (e1.sal < e2.sal )
);
SAL
5000
--求平均薪水等级最低的部门的部门名称
select dname ,t1.deptno ,grade, avg_sal from
(
select deptno, grade, avg_sal from
(select deptno, avg(sal) avg_sal from emp group by deptno) t
join salgrade s on (t.avg_sal between s.losal and hisal)
) t1
join dept on (t1.deptno =dept.deptno)
where t1.grade=
(
select min(grade) from
(
select deptno, grade, avg_sal from
(select deptno, avg(sal) avg_sal from emp group by deptno) t
join salgrade s on (t.avg_sal between s.losal and hisal)
)
)
DNAME DEPTNO GRADE AVG_SAL
SALES 30 3 1566.66667
--薪水最高的高的第3到6名雇员
select * from
(
select rownum rn,empno, ename ,sal from
(
select e.empno,ename,sal from emp e
join (select empno from emp where empno not in
(select mgr from emp where mgr is not null)) t
on e.empno= t.empno
order by sal desc
)
)where rn >=3 and rn <6;
RN EMPNO ENAME SAL
3 7934 MILLER 1300
4 7521 WARD 1250
5 7654 MARTIN 1250
rownum只能用于<,<=这么用
select rownum from
(
select rownum r ,ename from emp
) where r>10;
求薪水最高的前5人
select ename,sal from
(
select ename,sal from emp order by sal desc
)where rownum<=5;
ENAME SAL
KING 5000
SCOTT 3000
FORD 3000
JONES 2975
BLAKE 2850
薪水最高的5-10
select ename,sal from
(
select rownum r,ename,sal from emp order by sal desc
)where r<=10 and r>==5;
ENAME SAL
KING 5000
SCOTT 3000
BLAKE 2850
CLARK 2450
TURNER 1500
MARTIN 1250
SQL面试题:
有3个表S,C,SC
S(SNO,SNAME)代表(学号,姓名)
C(CNO,CNAME,CTEACHER)代表(课号,课名,教师)
SC(SNO,CNO,SCGRADE)代表(学号,课号成绩)
问题:
1.找出没选过"黎明"老师的所有学生姓名。
select SNAME from
S join SC on (S.SNO = SC.SNO) join
C on (C.CNO = SC.CNO) where Teacher <> '黎明';
/** 我写的
select SNAME from
(S join SC on (S.SNO = SC.SNO) ) T
where T.CNO in (select CNO from c where CTEACHER <> '黎明')
*/
2.列出2门以上(含2门)课不及格的学生的姓名及成绩。
select sname from s where sno in
(
select sno,count(*) from sc
where scgrade<60
group by sno having count(*) >= 2
);
3.即学过1号课程又学过2号课程的所有学生的姓名。
select sname from S
wehre sno in
(select sno from sc cno=1 t1
join seclec son from sc cno=2 t2 on t1.sno=t2.sno)
分享到:
相关推荐
Oracle复习总结Oracle复习总结Oracle复习总结Oracle复习总结Oracle复习总结Oracle复习总结
ORACLE复习纲要ORACLE复习纲要ORACLE复习纲要 杭电的
非常好的oracle学习笔记.是我花了一些心思从网上搞来再整理的。
oracle复习大纲,《Oracle数据库开发》考试题型包括单项选择题、判断题、填空题、简答题和应用题五种题型。应用题包括程序填空和编写程序题目。包括出题范围
临时抱抱佛脚,考前多看试卷有益健康。挂科影响身心健康!
oracle数据库考试复习题,oracle数据库考试复习题oracle数据库考试复习题oracle数据库考试复习题oracle数据库考试复习题
ORACLE复习资料 各种DML PLSQL实例
Oracle期末复习资料,大学的期末考试的必备复习资料
Oracle复习用脚本文件(相当全) 包括授权 查询 触发器 过程函数的调用
oracle复习的复习资料 oracle数据库基础教程
本科《ORACLE数据库》选修课 复习汇总
最新Oracle考试复习资料 最新的Oralce考试
2011年Oracle复习资料,考试必备
ORACLE复习资料学习资料重点 ORACLE复习资料学习资料重点
Oracle复习资料答案
用于Oracle复习
oracle 11g 复习题
Oracle Database,又名Oracle RDBMS,或简称Oracle。是甲骨文公司的一款关系数据库管理系统。它是在数据库领域一直处于领先地位的产品。可以说Oracle数据库系统是目前世界上流行的关系数据库管理系统,系统可移植性...
来自于国内知名学校的ftp上,请大家下载后学习,最后予以删除,这是尊重作者的体现
Oracle复习资料.docx