ImageVerifierCode 换一换
格式:DOCX , 页数:15 ,大小:18.73KB ,
资源ID:11090665      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/11090665.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(数据库面试宝典.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

数据库面试宝典.docx

1、数据库面试宝典数据库面试宝典一是关于怎样找出和去除重复数据,这在另一个帖子利已有详细介绍。二是关于找出某一列里最大或最小的前几个,或是大于或小于某一个值(最大值或平均值)的数据。针对这种情况,再此做一个介绍。1:找出公司里收入最高的前三名员工:SQL select rownum, last_name, salary2 from (select last_name, salary3 from s_emp4 order by salary desc)5 where rownum select rownum, last_name, salary2 from s_emp3 where rownum=3

2、4 order by salary desc; ROWNUM LAST_NAME SALARY- - - 1 Velasquez 4750 3 Nagayama 2660 2 Ngao 20002: 找出表中的某一行或某几行的数据:(1):找出表中第三行数据:用以下方法是不行的,因为rownum后面至可以用或号和其它的比较符号。SQL select * from s_emp2 where rownum=3;no rows selectedSQL select * from s_emp2 where rownum between 3 and 5;no rows selected正确的方法如下:S

3、QL l1 select last_name, salary2 from (select rownum a, b.*3 from s_emp b)4* where a=3SQL /LAST_NAME SALARY- -Nagayama 2660(2):找出第三行到第五行之间的数据:SQL l1 select last_name, salary2 from (select rownum a, b.*3 from s_emp b)4* where a between 3 and 5SQL /LAST_NAME SALARY- -Nagayama 2660Quick-To-See 2755Ropeb

4、urn 29453:找出那些工资高于他们所在部门的平均工资的员工。(1):第一种方法:SQL select last_name, dept_id, salary2 from s_emp a3 where salary(select avg(salary)4 from s_emp5 where dept_id=a.dept_id);LAST_NAME DEPT_ID SALARY- - -Velasquez 50 4750Urguhart 41 2280Menchu 42 2375Biri 43 2090Catchpole 44 2470Havel 45 2483.3Nguyen 34 2897

5、.5Maduro 41 2660Nozaki 42 2280Schwartz 45 209010 rows selected.(2):第二种方法:SQL l1 select a.last_name, a.salary, a.dept_id, b.avgsal2 from s_emp a, (select dept_id, avg(salary) avgsal3 from s_emp4 group by dept_id) b5 where a.dept_id=b.dept_id6* and a.salaryb.avgsalSQL /LAST_NAME SALARY DEPT_ID AVGSAL-

6、 - - -Velasquez 4750 50 3847.5Urguhart 2280 41 2181.5Menchu 2375 42 2055.16667Biri 2090 43 1710Catchpole 2470 44 1995Havel 2483.3 45 2069.1Nguyen 2897.5 34 2204Maduro 2660 41 2181.5Nozaki 2280 42 2055.16667Schwartz 2090 45 2069.110 rows selected.4:找出那些工资高于他们所在部门的manager的工资的员工。SQL l1 select id, last_

7、name, salary, manager_id2 from s_emp a3 where salary(select salary4 from s_emp5* where id=a.manager_id)SQL / ID LAST_NAME SALARY MANAGER_ID- - - - 6 Urguhart 2280 2 7 Menchu 2375 2 8 Biri 2090 2 9 Catchpole 2470 2 10 Havel 2483.3 2 12 Giljum 2831 3 13 Sedeghi 2878.5 3 14 Nguyen 2897.5 3 15 Dumas 275

8、5 3 16 Maduro 2660 610 rows selected.找出部门工资排名第二,三的员工1 select name,salary,deptno from (2 select concat(last_name,first_name) name,salary,department_id deptno,3 rank() over (partition by department_id order by salary desc) rnk4* from employees) where rnk=2 or rnk=3SQL /NAME- SALARY DEPTNO- -FayPat 600

9、0 20KhooAlexander 3100 30BaidaShelli 2900 30NAME- SALARY DEPTNO- -WeissMatthew 8000 50KauflingPayam 7900 50ErnstBruce 6000 60NAME- SALARY DEPTNO- -AustinDavid 4800 60PataballaValli 4800 60PartnersKaren 13500 80NAME- SALARY DEPTNO- -ErrazurizAlberto 12000 80KochharNeena 17000 90De HaanLex 17000 90NAM

10、E- SALARY DEPTNO- -FavietDaniel 9000 100ChenJohn 8200 100GietzWilliam 8300 11015 rows selected.SQL找出部门工资排名第二,三的员工1 select name,salary,deptno from (2 select concat(last_name,first_name) name,salary,department_id deptno,3 rank() over (partition by department_id order by salary desc) rnk4* from employe

11、es) where rnk=2 or rnk=3SQL /NAME- SALARY DEPTNO- -FayPat 6000 20KhooAlexander 3100 30BaidaShelli 2900 30NAME- SALARY DEPTNO- -WeissMatthew 8000 50KauflingPayam 7900 50ErnstBruce 6000 60NAME- SALARY DEPTNO- -AustinDavid 4800 60PataballaValli 4800 60PartnersKaren 13500 80NAME- SALARY DEPTNO- -Errazur

12、izAlberto 12000 80KochharNeena 17000 90De HaanLex 17000 90NAME- SALARY DEPTNO- -FavietDaniel 9000 100ChenJohn 8200 100GietzWilliam 8300 11015 rows selected.SQL又是一道面试题:原表:id proid proname1 1 M1 2 F2 1 N2 2 G3 1 B3 2 A查询后的表:id pro1 pro21 M F2 N G3 B A写出查询语句 又是一道面试题:原表:id proid proname1 1 M1 2 F2 1 N2

13、2 G3 1 B3 2 A查询后的表:id pro1 pro21 M F2 N G3 B A写出查询语句 又是一道面试题:原表:id proid proname1 1 M1 2 F2 1 N2 2 G3 1 B3 2 A查询后的表:id pro1 pro21 M F2 N G3 B A写出查询语句 又是一道面试题: 原表: id proid proname 1 1 M 1 2 F 2 1 N 2 2 G 3 1 B 3 2 A 查询后的表: id pro1 pro2 1 M F 2 N G 3 B A 写出查询语句 解决方案可有以下三种作参考:1:使用pl/sql代码实现,但要求你组合后的长度

14、不能超出oracle varchar2长度的限制。 下面是一个例子 create or replace type strings_table is table of varchar2(20);/create or replace function merge (pv in strings_table) return varchar2isls varchar2(4000);beginfor i in 1.pv.count loop ls := ls | pv(i);end loop;return ls;end;/create table t (id number,name varchar2(10

15、);insert into t values(1,Joan);insert into t values(1,Jack);insert into t values(1,Tom);insert into t values(2,Rose);insert into t values(2,Jenny);column names format a80;select t0.id,merge(cast(multiset(select name from t where t.id = t0.id) as strings_table) names from (select distinct id from t)

16、t0;drop type strings_table;drop function merge;drop table t;2:用sql: Well if you have a thoretical maximum, which I would assume you would given the legibility of listing hundreds of employees in the way you describe then yes. But the SQL needs to use the LAG function for each employee, hence a hundr

17、ed emps a hundred LAGs, so kind of bulky. This example uses a max of 6, and would need more cut n pasting to do more than that. SQL select deptno, dname, emps 2 from ( 3 select d.deptno, d.dname, rtrim(e.ename |, | 4 lead(e.ename,1) over (partition by d.deptno 5 order by e.ename) |, | 6 lead(e.ename

18、,2) over (partition by d.deptno 7 order by e.ename) |, | 8 lead(e.ename,3) over (partition by d.deptno 9 order by e.ename) |, | 10 lead(e.ename,4) over (partition by d.deptno 11 order by e.ename) |, | 12 lead(e.ename,5) over (partition by d.deptno 13 order by e.ename), ) emps, 14 row_number () over (partition by d.deptno 15 order by e.ename) x 16 from emp e, dept d 17 where d.deptno = e.deptno 18 ) 19 where x = 1 20 / DEPTNO DNAME EMPS - - - 10 ACCOUNTING CLARK, KING, MILLER 20 RESEARCH ADAMS, FO

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1