今天面试了一份数据库工程师题目,本人以前做编程的.有些不会做,现在贴出来,欢迎大家上机调试给出答案
1.有一关系数据库,三个基本表
S(Sno,Sname)
C(Cno,Cname,Cteacher)
SC(Sno,Cno,Scgrade)
1.找出没有选修过"李明"老师课程的所有学生姓名
2.列出二门以上(含两门)不及格课程的学生姓名与平均成绩
3.列出既学过"1"号,又学过"2"号课程的所有学生姓名
4.列出"1"号课程比"2"号课程成绩搞的所有学生学号
5.列出"1"号课的成绩比"2"号课成绩高的所有学生的学号及其"1"号课和"2"课的成绩问答题目:
1.oracle中如果经常出现死锁,应该考虑增加哪个配置参数
2.unio和union all的区别
3.SGA的组成
4.oracle中所占内存应该占物理内存的百分之几比较好?
5.建多列索引时,应该考虑什么?
6.在sybase中,如果日志满了,应该如何操作?如果不考虑备份,怎样清除?
7.sql查询中,一个大表和一个小表的关联查询,如何优化?sql调优
delete from test_table_1 a
where not exists(select * from test_table_2 b where a.parent_id=b.id)
其中,test_table_1表4百万,有索引字段,test_table_2表4万
现在查询60s,请写出优化的SQL语句
1.有一关系数据库,三个基本表
S(Sno,Sname)
C(Cno,Cname,Cteacher)
SC(Sno,Cno,Scgrade)
1.找出没有选修过"李明"老师课程的所有学生姓名
2.列出二门以上(含两门)不及格课程的学生姓名与平均成绩
3.列出既学过"1"号,又学过"2"号课程的所有学生姓名
4.列出"1"号课程比"2"号课程成绩搞的所有学生学号
5.列出"1"号课的成绩比"2"号课成绩高的所有学生的学号及其"1"号课和"2"课的成绩问答题目:
1.oracle中如果经常出现死锁,应该考虑增加哪个配置参数
2.unio和union all的区别
3.SGA的组成
4.oracle中所占内存应该占物理内存的百分之几比较好?
5.建多列索引时,应该考虑什么?
6.在sybase中,如果日志满了,应该如何操作?如果不考虑备份,怎样清除?
7.sql查询中,一个大表和一个小表的关联查询,如何优化?sql调优
delete from test_table_1 a
where not exists(select * from test_table_2 b where a.parent_id=b.id)
其中,test_table_1表4百万,有索引字段,test_table_2表4万
现在查询60s,请写出优化的SQL语句
解决方案 »
- oracle 安装卡住了,求帮助,谢谢各位。 急
- 我把ora11.2的UNDOTBS01.DBF给删了,怎么恢复呢?急!
- 被一个clob搞的加班,泪奔……(就剩20分了,抱歉)
- 可以这样使用decode函数吗?
- 求asp.net编程高手培训本人,培训费按天计算
- 基础数据删除的问题如何解决
- 为什么我装oracle数据库的时候会频繁死机啊???
- 简单问题
- 我装了9i,可以在服务器用sqlplus可能连上,但在其它机子就安不上了,我在用jbuilder的连接工具就能连,这是为什么啊,我怎么才能用其它工
- 谁能给我一个C/C++访问Oracle 的例程
- 求将两段日期合并的pl/sql方法
- *.exe可以正确运行,但是制作好的安装程序不能正确运行,涉及oracle数据库?
select sno,sname
from s
minus
select s.sno,s.sname
from s,c,sc
where s.sno=sc.sno
and c.cno=sc.cno
and c.Cteacher='李明'
group by s.sno,s.sname
select a.no,a.name,a.avg_sc
from(
select s.no,s.name,avg(scgrade) avg_sc,sum(decdoe(sign(sc.scrgde-60),-1,1,0)) no_pass
from s,sc
where s.sno=sc.sno
group by s.no,s.name
) a
where a.no_pass>=2
select a.sno,a.snmae
from
(select s.sno,s.sname,sc.cno,row_number() over(partition by s.sno,s.sname order by sc.cno) rn
from s,sc
where s.sno=sc.sno) a
where a.rn=2
select a.sno,a.snmae
from
(select s.sno,s.sname,sc.cno,row_number() over(partition by s.sno,s.sname order by sc.cno) rn
from s,sc
where s.sno=sc.sno
and sc.cno in ('1','2')
) a
where a.rn=2
select a.sno,a.snmae,a.c_1,a.c_2
from
(
select s.sno,s.sname,sum(decode(sc.cno,'1',sc.Scgrade,0)) c_1,sum(decode(sc.cno,'2',sc.Scgrade,0)) c_2
from s,sc
where s.sno=sc.sno
and sc.cno in ('1','2')
) a where
a.c_1>a.c_2
2 union 滤去重复的数据,union all不滤去重复的
7 from 大表,小表sql 优化也不知道对不对
delete from test_table_1 a
where not exists(select '1' from test_table_2 b where a.parent_id=b.id)
java pool
shared pool
large pool
块缓存区
UGA有时也在这里
日志缓冲区
还有一些记不清了
不知道是不是oracle默认的就是最好的,今天刚装了oracle11g,默认40%
Oracle此时会自动进行先扫描小表后扫描大表,关键就看Where子句各条件数据量的大小及其顺序了.
这样子优化的空间估计不大
如果a.parent_id,b.id是not null的话,可以改成not in, 或许会快点我写一个:delete
(
select 1
from test_table_2 a
left join test_table_1 b on a.parent_id = b.id
where b.id is null
)
select s.sno,s.sname
from s,sc,c
where s.sno=sc.sno and c.cno=sc.cno
and c.cteacher <>'李明'
2.
select s.sno,s.sname,avg(sc.scgrade)scgrade,count(*)
from s,sc,c
where s.sno=sc.sno and c.cno=sc.cno
and sc.scgrade<60
group by s.sno,s.sname having count(*)>=23.
select t.sname
from (select s.sno, s.sname
from s, sc, c
where s.sno = sc.sno
and c.cno = sc.cno
and c.cno = 1) t,
sc
where t.sno = sc.sno
and sc.cno = 24.
select sno
from (select s.sno,
max(case when sc.cno = 1 then sc.scgrade end )grade1,
max(case when sc.cno = 2 then sc.scgrade end )grade2
from s, sc, c
where s.sno = sc.sno
and c.cno = sc.cno group by s.sno)
where grade1 > grade25.
select sno,grade1,grade2
from (select s.sno,
max(case when sc.cno = 1 then sc.scgrade end )grade1,
max(case when sc.cno = 2 then sc.scgrade end )grade2
from s, sc, c
where s.sno = sc.sno
and c.cno = sc.cno group by s.sno)
where grade1 > grade2
select s.sno,s.sname
from s,sc,c
where s.sno=sc.sno and c.cno=sc.cno
and c.cteacher <>'李明' 这个错误,这样只是出来的人员名单中,还有会选择李明的人员,这样的结果只是显示所以选修剔掉李明之后的所有人的名单
假设a选了一门课,不是李明的
B选了两门课,一门是李明
你这样出来的结果是a和B,而实际题目要求的只会出现a
cno in
(select cno from c where cteacher ='李明'))
(select sno from (select sno,count(*) 'count'
from (select sno from sc where scgrade<60) a group by a.sno) b where b.count>1)
group by s.sname
(
select sno from sc where cno='1' and sno in(
select sno from sc where cno='2')
)
似乎可以把and c.cno=sc.cno 去掉
改成:
select s.sno,s.sname,avg(sc.scgrade)scgrade,count(*)
from s,sc,c
where s.sno=sc.sno and sc.scgrade <60
group by s.sno,s.sname having count(*)>=2 楼主以为如何?
表1:e_s;
表2:e_c;
表3:e_sc; -- 1、找出没有选修过"李明"老师课程的所有学生姓名
select * from e_s
where sno not in(
select c.sno
from e_c b,e_sc c ,e_s a
where b.cno = c.cno and b.cteacher ='李明' and a.sno = c.sno
); --2、列出二门以上(含两门)不及格课程的学生姓名与平均成绩
--(1)二门以上(含两门)不及格课程的学生姓名
select * from (
select count(sno) as gs, sname, sno
from (select a.sno, a.sname, b.cno, b.cname, b.cteacher, c.scgrade
from e_c b, e_sc c, e_s a
where b.cno = c.cno
and a.sno = c.sno
and c.scgrade <= '60')
group by sname, sno)
where gs >='2'; --(2)(含两门)不及格课程的学生姓名与平均成绩
select bb.sno,bb.sname,avg(scgrade)
from e_sc aa,
(
select * from (
select count(sno) as gs, sname, sno
from (select a.sno, a.sname, b.cno, b.cname, b.cteacher, c.scgrade
from e_c b, e_sc c, e_s a
where b.cno = c.cno
and a.sno = c.sno
and c.scgrade <= '60')
group by sname, sno)
where gs >='2'
) bb
where aa.sno = bb.sno
group by bb.sno,bb.sname;
--3、列出既学过"1"号,又学过"2"号课程的所有学生姓名
select t.sno,t.sname from e_s t,
(
select a.sno, a.cno,a.scgrade,b.cno,b.scgrade from
(select sno,cno,scgrade from e_sc where cno=1)a,
(select sno,cno,scgrade from e_sc where cno=2)b
where a.sno = b.sno
)d
where t.sno = d.sno;
--4、列出"1"号课程比"2"号课程成绩高的所有学生学号
select sno from
(
select a.sno,
a.cno,
a.scgrade as scgrade_1,
--b.sno,
b.cno,
b.scgrade as scgrade_2,
(a.scgrade - b.scgrade)as fsjg
from
(select sno,cno,scgrade from e_sc where cno=1)a,
(select sno,cno,scgrade from e_sc where cno=2)b
where a.sno = b.sno
)where fsjg > 0
--5、列出"1"号课的成绩比"2"号课成绩高的所有学生的学号及其"1"号课和"2"课的成绩
select sno,scgrade_1,scgrade_2 from
(
select a.sno,
a.cno,
a.scgrade as scgrade_1,
--b.sno,
b.cno,
b.scgrade as scgrade_2,
(a.scgrade - b.scgrade)as fsjg
from
(select sno,cno,scgrade from e_sc where cno=1)a,
(select sno,cno,scgrade from e_sc where cno=2)b
where a.sno = b.sno
)where fsjg > 0