Ⅰ java,oracle面试题,如下,sql怎么写
如题我先进行分析:
第一句话中按月找出平均 填写时间大于3天的人员信息 :
那么可用理解为 根据月份查找 员工平均延迟填写日期大于3天的 人员信息。
第二句话一个人员的日志填写日期有多条则取最早的一条,如果有一天未填写,则取系统当前时间,不含小时。
以上这句话需要注意两点 第一点,取最早的一条此处需要用到ROW_NUMBER() OVER() 以及未填写 则取系统当前时间 不含小时 那么取值格式应为yyyy-mm-dd此处需要处理格式。
根据以上分析提供如下SQL: 注:(以下SQL已ORACLE为例)
--创建临时表存储数据
withemp_logas(
select1asempno,'张一'asempname,'工作内容1'asworkcontent,date'2017-03-20'asbegdate,date'2017-03-23'asentrydate,1asnumfromal
unionall
select1asempno,'张一'asempname,'工作内容2'asworkcontent,date'2017-03-20'asbegdate,date'2017-03-23'asentrydate,2asnumfromal
unionall
select1asempno,'张一'asempname,'工作内容3'asworkcontent,date'2017-03-20'asbegdate,date'2017-03-24'asentrydate,5asnumfromal
unionall
select1asempno,'张一'asempname,'工作内容1'asworkcontent,date'2017-03-24'asbegdate,date'2017-03-30'asentrydate,8asnumfromal
unionall
select2asempno,'张二'asempname,'工作内容21'asworkcontent,date'2017-03-20'asbegdate,date'2017-03-30'asentrydate,8asnumfromal
unionall
select2asempno,'张二'asempname,'工作内容22'asworkcontent,date'2017-03-25'asbegdate,date'2017-03-28'asentrydate,8asnumfromal
unionall
select3asempno,'张三'asempname,'工作内容31'asworkcontent,date'2017-03-20'asbegdate,nullasentrydate,nullasnumfromal
unionall
select3asempno,'张三'asempname,'工作内容32'asworkcontent,date'2017-03-20'asbegdate,nullasentrydate,nullasnumfromal
unionall
select4asempno,'张四'asempname,'工作内容42'asworkcontent,date'2017-03-25'asbegdate,date'2017-03-28'asentrydate,8asnumfromal
)
select*from(
selectempno,empname,sum(num)num,sum(yanci)/count(empno)pingjunyanci--获取人员当月总延迟数除去当月人员每日的打开数计算出当月每天的平均延迟天数
from(selectROW_NUMBER()OVER(PARTITIONBYe.empno,e.begdateORDERBYe.empno,e.begdate)ASRN,--排序获取当天有多条记录并在后面条件中获取第一条
e.empno,e.empname,
e.workcontent,e.begdate,
e.entrydate,
e.num,
(nvl(e.entrydate,to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'))-begdate)asyanci--判断如果没有填写结束日期那么以系统当前日期进行运算延迟日期
fromemp_loge)e1
wheree1.rn=1--获取第一条
andto_char(begdate,'yyyy-mm')='2017-03'--可用的月份条件
groupbyempno,empname,numorderbyempno--根据人员工号、人员姓名分组汇总
)e2wheree2.pingjunyanci>3;
--分析不易忘认真阅读后采纳,有其他问题请追问我。
Ⅱ ORACLE数据库面试题
1.
update t
set logdate=to_date('2003-01-01','yyyy-mm-dd')
where logdate=to_date('2001-02-11','yyyy-mm-dd');
2.
select *
from t
where name in (select name from t group by name having coung(*)>1)
order by name;--没说清楚,到底是升序还是降序
3.
select ID,NAME,ADDRESS,PHONE,LOGDATE
from
(
select t.*,row_number() over(partition by name order by name) rn
from t
)
where rn = 1;
4.
update t
set (address,phone)=
(select address,phone from e where e.name=t.name);
5.
select *
from t
where rownum <=5
minus
select *
from t
where rownum <=2;
也没什么特别的地方,有些题目用oracle特有的函数去做会比较简单,像在第三题中用到的oracle的分析函数,以及在第一题中用到的oracle的to_char()函数。
这几个题目主要是看你能不能使用oracle的函数去处理
Ⅲ sql面试题
1.
select
s.title,
count(p.id)
from
书表
s
left
join
评论
p
on
s.id=p.书表中的id
group
by
s.title
(注意:左外连接的作用是将评价数为0的书显示出来.count(p.id)和count(*)的区别是count(p.id)不计入p.id为null的行)
2.
select
top
1
s.title,
count(p.id)
from
书表
s
left
join
评论
p
on
s.id=p.书表中的id
group
by
s.title
order
by
2
desc
(以第2列倒序排序,取第1行)
Ⅳ sql语句 面试题
A.创建表格CODE省略
注明:学生表PK stu_id 课程表pk cos_id 分数表PK enrollment_id FK stu_id,cos_id
B.插入数据code省略
C.Query
select s.stu_id,stu_name,count(cos_id) from student s,enrollments e where s.stu_id = e.stu_id and e.grade>60 group by s.stu_id,stu_name;
select e.stu_id,s.stu_name,c.cos_name from student s,enrollments e,course c
where s.stu_id = e.stu_id
and e.cos_id = c.cos_id
and c.cos_name = 'CHINESE'
and s.stu_name like 'W%';
select stu_id,stu_name from (select e.stu_id,stu_name,cos_name from enrollments e,student s,course c
where s.stu_id = e.stu_id
and e.cos_id = c.cos_id
and c.cos_name IN ('CHINESE','MUSIC'))
group by stu_id,stu_name
having count(cos_name) = 2
select distinct e.cos_id,c.cos_name,count(e.stu_id) stu_count,count(e.stu_id)-NVL(A.FAIL,0) upscore,(count(e.stu_id)-NVL(A.FAIL,0))/count(e.stu_id) rate from
(select cos_id,count(stu_id) fail from enrollments where grade<60 group by cos_id) a,enrollments e,course c
where e.cos_id = a.cos_id(+)
and e.cos_id = c.cos_id
group by e.cos_id,NVL(a.fail,0),c.cos_name;
update student
set avg_grade =(select avg(grade) X from enrollments group by stu_id
having student.stu_id = enrollments.stu_id);
select stu_id,avg(grade) from
(select stu_id,cos_id,grade,row_number() over(partition by stu_id order by grade ) X from enrollments)
group by stu_id
having count(*)<=2
UNION
select A.stu_id,avg(A.grade)from
(select stu_id,cos_id,grade,row_number() over(partition by stu_id order by grade ) X from enrollments) A,
(select stu_id,count(*) c from
(select stu_id,cos_id,grade,row_number() over(partition by stu_id order by grade ) X from enrollments)
group by stu_id) B
where A.stu_id = B.stu_id
and A.x>1 and x<B.c
group by A.stu_id,b.c
_________________________________________________
环境:oracle 10g/TOAD 以上代码均通过测试,如有问题,请联系,谢谢
Ⅳ oracle sql 语句 面试题
(1)统计有学生选修的课程门数
select count(distinct c#) from SC
2)求选修C4课程的女学生的平均年龄
select avg(s.age) --最好都带上前缀,养成好习惯
from s,c,sc where s.s#=sc.s# and c.c#=sc.c#
and c.cname='C4' and s.sex='女'--字符类型带引号,必须注意大小写,你那么写好麻烦
3)求刘老师所授的课程的每门课程的平均成绩
select c.cname , avg(grade) from sc , c
where c.teacher =' liu' and sc.c# = c.c#
group by c.cname --select后是什么字段,这地方你也得最少有这个字段
(4)统计每门课程的学生选修人数(超过10人的课程才统计)。要求显示课程号和人数,查询结果按人数降序排列,若人数相同,按课程号升序排列。
select t.*
from
(select sc.c#, count(s#) counnt_s from s,sc where s.s# = sc.s# group by sc.c# having count(s#) >10) t
order by counnt_s desc,c# asc --你排序不对,另外oracle不可根据别名排序,只可再做嵌套
5)检索学号比王军同学大,而年龄比他小的学生姓名
select a.s#
from
(select s# from s where s#>(select s# from s where sname='王军') a,
select s# from s where age>(select age from s where sname='王军') b
where a.s#=b.s#
6)求年龄大于女同学平均年龄的男学生的姓名和年龄
select sname,age from s
where age>
(select avg(age) from s where sex = 'nv') and sex = 'nan' --没问题
7)求年龄大于所有女同学年龄的男学生的姓名和年龄
select sname ,age from s
where age>(select max(age) from s where sex = 'nv') and sex = 'nan' --没问题
Ⅵ oracle学习新手,求几条sql的标准答案对照~~~
1、
select EID,Fname from
(select rownum id,E.EID,E.Fname from Employee E,Department D where E.DID=D.DID and D.Name='research' order by DOB desc)
where id=2;
2、
select EID,Fname from Employee where Fname like '%Y%' order by Fname desc;
3、
select Fname from Employee where DOB<(select agv(DOB) from Employee);
4、
select D.DID,D.Name,count(P.PID) from Department D,Project P where D.DID=P.DID group by D.DID,D.Name;
5、
select Fname from
(select E.EID,E.Fname Employee E,Work_On W where E.EID=W.PID group by E.EID,E.Fname having count(W.PID)=1);
6、
select Fname from
(select E.EID,E.Fname Employee E,Work_On W where E.EID=W.PID group by E.EID,E.Fname having count(W.PID)>=1);
7、
select Fname,project数量 from
(select E.EID,E.Fname,count(W.PID) project数量 Employee E,Work_On W where E.EID=W.PID group by E.EID,E.Fname);
8、
select A.EID,A.Fname,A.project数量 maleproject数量,B.project数量 femaleproject数量 from
(select E.EID,E.Fname,count(W.PID) project数量 Employee E,Work_On W where E.EID=W.PID and E.Gender='male' group by E.EID,E.Fname)A,
(select E.EID,E.Fname,count(W.PID) project数量 Employee E,Work_On W where E.EID=W.PID and E.Gender='female' group by E.EID,E.Fname)B;
where A.EID=B.EID;
9、
select P.Name,count(W.EID) Work_On W,Project P where W.PID=P.PID group by P.Name;
---
以上,希望对你有所帮助。
Ⅶ Oracle面试题 求解答
8. 汇总统计收款总金额(CHARGE_TOTAL)按各收费员(CHARGE_MAN)分别汇总,结果如下所示:
CHARGE_MAN C1
0006 3065.66
测试61 144153
李世民 85
SQL:select CHARGE_MAN,sum(CHARGE_TOTAL) as C1 from rcs_znj_2007 order by CHARGE_MAN
9. 按照DISP_ORDER升序显示CHAR_LIST表数据内容
SQL:select * from char_list order by DISP_ORDER
10. 按照ADJ_TYPE(减免类别)升序,显示RCS_ZNJ_2007表所有内容,其中ADJ_TYPE字段须转换成对应的中文字符(CHAR_LIST.LIST_STRING)。(两表关联查询)
SQL: select ID,METERNO,
(select LIST_STRING from CHAR_LIST where LIST_CHAR = ADJ_TYPE) as ADJ_NAME,
CHARGE_DATE,
CHARGE_TOTAL,CHARGE_MAN
from RCS_ZNJ_2007 order by ADJ_TYPE
11. 根据CHAR_LIST表内容,将RCS_ZNJ_2007表中ADJ_TYPE字段值全部更新成对应的中文字符(CHAR_LIST.LIST_STRING)。
SQL: update RCS_ZNJ_2007 set ADJ_TYPE = (select LIST_STRING from CHAR_LIST where LIST_CHAR = ADJ_TYPE)
Ⅷ oracle几道简单面试题,请大侠帮忙
1,数据库迁移需要考虑的问题很多,这个一句两句也说不完;
2,首先考虑的就是数据量,如果是小表,没有索引反而访问还要快一些。
3,权衡全表还是走索引,看SQL的执行计划就可以了;
4,这个数据库对象是用在两个数据库之间联接,交换,查询数据用的。
5,去数据库里查锁住的进程,杀了就可以了。之后再分析原因。
6,分区表是数据量大于1.5gb以上才用的吧。
7,临时表空间当然会满,查视图也是一样的。
8,开了归档就相当于win系统的设置里开了系统还原一样。
9,redo这个设置要看实际情况,根据主机CUP处理能力,数据库优化参数等因素决定的。
Ⅸ 面试的时候问你熟悉oracle数据库吗
如果是开发的话,那还是基于SQL这种语言的语法了,要多自己使用才能熟悉的。 对于oracle数据库来说,PL/SQL delelopment是重点,除了SQL,还要了解触发器trigger,存储过程procere,任务job,视图view等等。
Ⅹ SQL面试题
翻译
题目很简单,楼主看看
MovieBuster在线电影收看服务拥有如下信息的数据库:
(*)号表示外键参考,
电影信息表:MovieInfo(mvID, title, rating, year, length, studio)
分类信息表:GenreInfo(mvID*, genre)
工作室信息表:DirectInfo(mvID*, director)
电影信息表主要存放电影的相关信息,其中主键mvID是电影出产时人为给定的一个ID值,一个电影可能拥有多个类别并且有多个工作室一起生产。
注意这些表与数据库中的其他表名已经区别开来。
一个只读数据信息已经被建立在oracle上并且可以通过如下命令sqlmb1获得信息。作为选择,你可以通过此建立自己的数据表。
数据可以从黑板上看到
从数据库中查询如下问题并给出正确答案:
(1)工作室 "Paramount Pictures"已经生产多少部 rating="G" 并且年份在1940-1950年之间的电影?
(2)查出rating ="PG" 生产年份在1940之前或者2000年之后的电影的总数。
(3)列出每种分类的电影数,查出结果按电影分数总数降序排序。
(4)查找出生产的电影平均长度至少大于等于3的工作室的名字以及对应的平均电影长度。