SQL数据库经典面试题(修改笔试题)(有答案)

上传人:飞****9 文档编号:149053998 上传时间:2020-10-24 格式:DOCX 页数:41 大小:146.86KB
返回 下载 相关 举报
SQL数据库经典面试题(修改笔试题)(有答案)_第1页
第1页 / 共41页
SQL数据库经典面试题(修改笔试题)(有答案)_第2页
第2页 / 共41页
SQL数据库经典面试题(修改笔试题)(有答案)_第3页
第3页 / 共41页
SQL数据库经典面试题(修改笔试题)(有答案)_第4页
第4页 / 共41页
SQL数据库经典面试题(修改笔试题)(有答案)_第5页
第5页 / 共41页
点击查看更多>>
资源描述

《SQL数据库经典面试题(修改笔试题)(有答案)》由会员分享,可在线阅读,更多相关《SQL数据库经典面试题(修改笔试题)(有答案)(41页珍藏版)》请在金锄头文库上搜索。

1、,.28.数据库:抽出部门,平均工资,要求按部门的字符串顺序排序,不能含有humanresource部门, employee结构如下:employee_id, employee_name,depart_id,depart_name,wage答:select depart_name, avg(wage)from employee where depart_name human resourcegroup by depart_name order by depart_name-29.给定如下 SQL 数据库: Test(num INT(4)请用一条 SQL 语句返回 num的最小值,但不许使用统计

2、功能,如MIN ,MAX 等答 :select top 1 num from Test order by num-33. 一个数据库中有两个表 :一张表为 Customer,含字段 ID,Name;一张表为 Order ,含字段 ID,CustomerID(连向 Customer中 ID 的外键) ,Revenue;写出求每个 Customer的 Revenue总和的 SQL 语句。建表create table customer(ID int primary key,Name char(10)gocreate table order(ID int primary key,CustomerIDi

3、nt foreign key referencescustomer(id) , Revenue float)go- 查询select Customer.ID, sum( isnull(Order.Revenue,0) )from customer full join order on( order.customerid=customer.id )group by customer.id; .,.selectcustomer.id,sum(order.revener)fromorder,customerwherecustomer.id=customeridgroup by customer.id

4、select customer.id, sum(order.revener )from customer full join orderon( order.customerid=customer.id )group by customer.id5 数据库( 10 )a tabel called“ performance” contain:ame and score, please用 SQL语言表述如何选出 score 最 high 的一个(仅有一个)仅选出分数, Select max(score) from performance仅选出名字,即选出名字,又选出分数:selecttop 1 sc

5、ore ,namefrom per order by scoreselect name1,score from per where score in/=(select max(score) from per).4 有关系 s(sno,sname) c(cno,cname) sc(sno,cno,grade) 1 问上课程 db 的学生 noselect count(*) from c,sc where ame=db and o=oselect count(*) from sc where cno=(select cno from c where ame=db)2 成绩最高的学生号select

6、sno from sc where grade=(select max(grade) from sc )3 每科大于 90 分的人数select ame,count(*) from c,sc o=o andsc.grade90group by ameselect ame,count(*) from c join o=o andsc.grade90group by ame数据库笔试题*建表:dept:deptno(primary key),dname,locemp:empno(primary key),ename,job,mgr,sal,deptno*/1 列出 emp 表中各部门的部门号,最高

7、工资,最低工资select max(sal) as最高工资 ,min(sal) as最低工资 ,deptno from emp groupby deptno; .,.2 列出 emp 表中各部门 job 为 CLERK 的员工的最低工资,最高工资select max(sal) as最高工资 ,min(sal) as最低工资 ,deptno as部门号 fromemp where job = CLERK group by deptno;3 对于 emp 中最低工资小于 1000 的部门,列出 job 为CLERK 的员工的部门号,最低工资,最高工资select max(sal) as最高工资 ,

8、min(sal) as最低工资 ,deptno as部门号 fromemp as bwhere job=CLERK and 1000(select min(sal) from emp as a where a.deptno=b.deptno) group by b.deptno4 根据部门号由高而低,工资有低而高列出每个员工的姓名,部门号,工资select deptno as 部门号 ,ename as 姓名 ,sal as 工资 from emp order by deptno desc,sal asc5 写出对上题的另一解决方法(请补充)6 列出 张三 所在部门中每个员工的姓名与部门号se

9、lect ename,deptno from emp where deptno = (select deptno from emp where ename = 张三 )7 列出每个员工的姓名,工作,部门号,部门名select ename,job,emp.deptno,dept.dname from emp,dept where emp.deptno=dept.deptno8 列出 emp 中工作为 CLERK 的员工的姓名,工作,部门号,部门名 select ename,job,dept.deptno,dname from emp,dept where dept.deptno=emp.dept

10、no and job=CLERK9 对于 emp 中有管理者的员工,列出姓名,管理者姓名(管理者外键为mgr )select a.ename as姓名 ,b.ename as管理者from emp as a,emp as bwhere a.mgr is not null and a.mgr=b.empno10 对于 dept 表中,列出所有部门名,部门号,同时列出各部门工作为 CLERK 的员工名与工作select dname as部门名 ,dept.deptno as部门号 ,ename as员工名 ,job as工作 from dept,empwhere dept.deptno *= em

11、p.deptno and job = CLERK11 对于工资高于本部门平均水平的员工,列出部门号,姓名,工资,按部门号排序select a.deptno as部门号 ,a.ename as姓名 ,a.sal as工资 from emp as awhere a.sal(select avg(sal) from emp as b where a.deptno=b.deptno)order by a.deptno12 对于 emp ,列出各个部门中平均工资高于本部门平均水平的员工数和部门号,按部门号排序select count(a.sal) as 员工数 ,a.deptno as 部门号 from

12、 emp as a where a.sal(select avg(sal) from emp as b where a.deptno=b.deptno)group by a.deptno order by a.deptno; .,.13 对于 emp 中工资高于本部门平均水平,人数多与 1 人的,列出部门号,人数,按部门号排序select count(a.empno) as员工数 ,a.deptno as部门号 ,avg(sal) as平均工资 from emp as awhere (select count(c.empno) from emp as c where c.deptno=a.de

13、ptno and c.sal(select avg(sal) from emp as b where c.deptno=b.deptno)1 group by a.deptno order by a.deptno14 对于 emp 中低于自己工资至少 5 人的员工,列出其部门号,姓名,工资,以及工资少于自己的人数select a.deptno,a.ename,a.sal,(select count(b.ename) from emp as bwhere b.sala.sal) as人数 from emp as awhere (select count(b.ename) from emp as b where b.sal5数据库笔试题及答案第一套一. 选择题1. 下面叙述正确的是 CCBAD _ 。A、算法的执行效率与数据的存储结构无关B、算法的空间复杂度是指算法程序中指令 ( 或语句 ) 的条数C、算法的有穷性是指算法必须能在执行有限个步骤之后终止 D 、以上三种描述都不对2. 以下数据结构中不属于线性数据结构的是 _ 。A、队列 B、线性表 C、二叉树 D、栈3. 在一棵二叉树上第 5 层的结点数最多是 _ 。A 、8 B 、 16 C 、32 D 、

展开阅读全文
相关资源
相关搜索

当前位置:首页 > IT计算机/网络 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号