Oracle面试题集锦 联系客服

发布时间 : 星期一 文章Oracle面试题集锦更新完毕开始阅读6e4755176c175f0e7cd137d4

name kecheng fenshu 张三语文 81 张三数学 75 李四语文 76 李四数学 90 王五语文 81 王五数学 100 王五英语 90

A: select distinct name from table where name not in (select distinct name from table where fenshu<=80) 6. 学生表如下:

自动编号学号姓名课程编号课程名称分数

1 2005001 张三 0001 数学 69 2 2005002 李四 0001 数学 89 3 2005001 张三 0001 数学 69

? 删除除了自动编号不同,其他都相同的学生冗余信息

A: delete tablename where 自动编号 not in(select min(自动编号) from tablename group by 学号,姓名,课程编号,课程名称,分数)

7. 一个叫department的表,里面只有一个字段name,一共有4条纪录,分别是a,b,c,d,

对应四个球对,现在四个球对进行比赛,用一条sql语句显示所有可能的比赛组合.

你先按你自己的想法做一下,看结果有我的这个简单吗?

答:select a.name, b.name from team a, team b where a.name < b.name 8. 请用SQL语句实现:从TestDB数据表中查询出所有月份的发生额都比101科目相应月份的发生额高的科目。请注意:TestDB中有很多科目,都有1-12月份的发生额。

AccID:科目代码,Occmonth:发生额月份,DebitOccur:发生额。 数据库名:JcyAudit,数据集:Select * from TestDB

答:select a.* from TestDB a ,(select Occmonth,max(DebitOccur) Debit101ccur from TestDB where AccID='101' group by Occmonth) b where a.Occmonth=b.Occmonth and a.DebitOccur>b.Debit101ccur 9. 面试题:表操作

? 说明:复制表(只复制结构,源表名:a 新表名:b) SQL: select * into b from a where 1<>1

? 说明:拷贝表(拷贝数据,源表名:a 目标表名:b) SQL: insert into b(a, b, c) select d,e,f from b;

? 说明:显示文章、提交人和最后回复时间

SQL: select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b

? 说明:外连接查询(表名1:a 表名2:b)

SQL: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c

? 说明:日程安排提前五分钟提醒

SQL: select * from 日程安排 where datediff('minute',f开始时间,getdate())>5

? 说明:两张关联表,删除主表中已经在副表中没有的信息

SQL: delete from info where not exists ( select * from infobz where info.infid=infobz.infid )

10. 一道SQL语句面试题,关于group by 表内容: 2005-05-09 胜 2005-05-09 胜 2005-05-09 负 2005-05-09 负 2005-05-10 胜 2005-05-10 负 2005-05-10 负

如果要生成下列结果, 该如何写sql语句? 胜 负 2005-05-09 2 2 2005-05-10 1 2

------------------------------------------

create table #tmp(rq varchar(10),shengfu nchar(1)) insert into #tmp values('2005-05-09','胜') insert into #tmp values('2005-05-09','胜') insert into #tmp values('2005-05-09','负') insert into #tmp values('2005-05-09','负') insert into #tmp values('2005-05-10','胜') insert into #tmp values('2005-05-10','负')

insert into #tmp values('2005-05-10','负')

? select rq, sum(case when shengfu='胜' then 1 else 0 end)'胜',sum(case when

shengfu='负' then 1 else 0 end)'负' from #tmp group by rq ? 2) select N.rq,N.勝,M.負 from ( select rq,勝=count(*) from #tmp where

shengfu='胜'group by rq)N inner join (select rq,負=count(*) from #tmp where shengfu='负'group by rq)M on N.rq=M.rq

? 3)select a.col001,a.a1 胜,b.b1 负 from (select col001,count(col001) a1

from temp1 where col002='胜' group by col001) a, (select

col001,count(col001) b1 from temp1 where col002='负' group by col001) b where a.col001=b.col001

11. 请教一个面试中遇到的SQL语句的查询问题

表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列。

select (case when a>b then a else b end ), (case when b>c then b esle c end) from table_name

12. 有一张表,里面有3个字段:语文,数学,英语。其中有3条记录分别表示语文70

分,数学80分,英语58分,请用一条sql语句查询出这三条记录并按以下条件显示出来(并写出您的思路):

大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及格。 显示格式:

语文 数学 英语 及格 优秀 不及格

select (case when 语文>=80 then '优秀' when 语文>=60 then '及格' else '不及格') as 语文, (case when 数学>=80 then '优秀' when 数学>=60 then '及格'else '不及格') as 数学, (case when 英语>=80 then '优秀' when 英语>=60 then '及格' else '不及格') as 英语, from table

13. 一个表中的Id有多个记录,把所有这个id的记录查出来,并显示共有多少条记录

数。

select id, Count(*) from tb group by id having count(*)>1

select * from(select count(ID) as count from table group by ID)T where T.count>1 14. 有两个表A和B,均有key和value两个字段,如果B的key在A中也有,就把B

的value换为A中对应的value这道题的SQL语句怎么写?

update b set b.value=(select a.value from a where a.key=b.key) where b.id in(select b.id from b,a where b.key=a.key);