资源描述:
《Oracle面试题及答案整理.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Oracle面试题及答案整理1、表:table1(FId,Fclass,Fscore),用最高效最简单的SQL列出各班成绩最高的列表,显示班级,成绩两个字段。selectfclass,max(fscore)fromtable1groupbyfclass,fid2、有一个表table1有两个字段FID,Fno,字都非空,写一个SQL语句列出该表中一个FID对应多个不同的Fno的纪录。类如: 101a1001 101a1001 102a1002 102a1003 103a1004 104a1005 104a1006 105a1007 105a
2、1007 105a1007 结果: 102a1002 102a1003 104a1005 104a1006selectt2.*fromtable1t1,table1t2wheret1.fid=t2.fidandt1.fno<>t2.fno;3、有员工表empinfo ( Fempnovarchar2(10)notnullpk, Fempnamevarchar2(20)notnull, Fagenumbernotnull, Fsalarynumbernotnull ); 假如数据量很大约1000万条;写一个你认为最高效的SQL,用一个SQL
3、计算以下四种人: fsalary>9999andfage>35 fsalary>9999andfage<35 fsalary<9999andfage>35 fsalary<9999andfage<35 每种员工的数量; selectsum(casewhenfsalary>9999andfage>35then1else0end)as"fsalary>9999_fage>35",sum(casewhenfsalary>9999andfage<35then1else0end)as"fsalary>9999_fage<35",sum(casewh
4、enfsalary<9999andfage>35then1else0end)as"fsalary<9999_fage>35",sum(casewhenfsalary<9999andfage<35then1else0end)as"fsalary<9999_fage<35"fromempinfo;4、表A字段如下 monthpersonincome 月份人员收入 要求用一个SQL语句(注意是一个)的处所有人(不区分人员)每个月及上月和下月的总收入 要求列表输出为 月份当月收入上月收入下月收入 MONTHSPERSONINCOME-------
5、-----------------------200807mantisXF5000200806mantisXF23500200806mantisXF33000200805mantisXF12000200805mantisXF62200200804mantisXF718002008038mantisXF40002008029mantisXF420020080210mantisXF330020080111mantisXF460020080911mantisXF680011rowsselectedselectmonths,max(incomes
6、),max(prev_months),max(next_months)from(selectmonths,incomes,decode(lag(months)over(orderbymonths),to_char(add_months(to_date(months,'yyyymm'),-1),'yyyymm'),lag(incomes)over(orderbymonths),0)asprev_months,decode(lead(months)over(orderbymonths),to_char(add_months(to_date(m
7、onths,'yyyymm'),1),'yyyymm'),lead(incomes)over(orderbymonths),0)asnext_monthsfrom(selectmonths,sum(income)asincomesfromagroupbymonths)aa)aaagroupbymonths;MONTHSMAX(INCOMES)MAX(PREV_MONTHS)MAX(NEXT_MONTHS)------------------------------------------------------20080146000750
8、020080275004600400020080340007500180020080418004000420020080542001800650020080665004200500020080