SQL数据库试题笔试题.docx
《SQL数据库试题笔试题.docx》由会员分享,可在线阅读,更多相关《SQL数据库试题笔试题.docx(79页珍藏版)》请在冰豆网上搜索。
SQL数据库试题笔试题
28.
数据库:
抽出部门,平均工资,要求按部门的字符串顺序排序,不能含有"humanresource"部门,
employee结构如下:
employee_id,employee_name,depart_id,depart_name,wage
答:
selectdepart_name,avg(wage)
fromemployee
wheredepart_name<>'humanresource'
groupbydepart_name
orderbydepart_name
--------------------------------------------------------------------------
29.
给定如下SQL数据库:
Test(numINT(4))请用一条SQL语句返回num的最小值,但不许使用统计功能,如MIN,MAX等
答:
selecttop1num
fromTest
orderbynum
--------------------------------------------------------------------------
33.一个数据库中有两个表:
一张表为Customer,含字段ID,Name;
一张表为Order,含字段ID,CustomerID(连向Customer中ID的外键),Revenue;
写出求每个Customer的Revenue总和的SQL语句。
建表createtablecustomer
(
IDintprimarykey,Namechar(10)
)
go
createtable[order]
(
IDintprimarykey,CustomerID intforeignkeyreferencescustomer(id),Revenuefloat
)
go
--查询
selectCustomer.ID,sum(isnull([Order].Revenue,0))
fromcustomerfulljoin[order]
on([order].customerid=customer.id)
groupbycustomer.id
selectcustomer.id,sum(order.revener)fromorder,customerwherecustomer.id=customeridgroupbycustomer.id
selectcustomer.id,sum(order.revener)
fromcustomerfulljoinorder
on(order.customerid=customer.id)
groupbycustomer.id
5数据库(10)
atabelcalled“performance”contain:
nameandscore,please用SQL语言表述
如何选出score最high的一个(仅有一个)
仅选出分数,Selectmax(score)fromperformance
仅选出名字,即选出名字,又选出分数:
selecttop1score,namefromperorderbyscore
selectname1,scorefromperwherescorein/=(selectmax(score)fromper)
.....
4有关系s(sno,sname)c(cno,cname)sc(sno,cno,grade)
1问上课程"db"的学生no
selectcount(*)fromc,scwhereame='db'ando=o
selectcount(*)fromscwherecno=(selectcnofromcwhereame='db')
2成绩最高的学生号
selectsnofromscwheregrade=(selectmax(grade)fromsc)
3每科大于90分的人数
selectame,count(*)fromc,scwhereo=oandsc.grade>90groupbyame
selectame,count(*)fromcjoinscono=oandsc.grade>90groupbyame
数据库笔试题
*
建表:
dept:
deptno(primarykey),dname,loc
emp:
empno(primarykey),ename,job,mgr,sal,deptno
*/
1列出emp表中各部门的部门号,最高工资,最低工资
selectmax(sal)as最高工资,min(sal)as最低工资,deptnofromempgroupbydeptno;
2列出emp表中各部门job为'CLERK'的员工的最低工资,最高工资
selectmax(sal)as最高工资,min(sal)as最低工资,deptnoas部门号fromempwherejob='CLERK'groupbydeptno;
3对于emp中最低工资小于1000的部门,列出job为'CLERK'的员工的部门号,最低工资,最高工资
selectmax(sal)as最高工资,min(sal)as最低工资,deptnoas部门号fromempasb
wherejob='CLERK'and1000>(selectmin(sal)fromempasawherea.deptno=b.deptno)groupbyb.deptno
4根据部门号由高而低,工资有低而高列出每个员工的姓名,部门号,工资
selectdeptnoas部门号,enameas姓名,salas工资fromemporderbydeptnodesc,salasc
5写出对上题的另一解决方法
(请补充)
6列出'张三'所在部门中每个员工的姓名与部门号
selectename,deptnofromempwheredeptno=(selectdeptnofromempwhereename='张三')
7列出每个员工的姓名,工作,部门号,部门名
selectename,job,emp.deptno,dept.dnamefromemp,deptwhereemp.deptno=dept.deptno
8列出emp中工作为'CLERK'的员工的姓名,工作,部门号,部门名
selectename,job,dept.deptno,dnamefromemp,deptwheredept.deptno=emp.deptnoandjob='CLERK'
9对于emp中有管理者的员工,列出姓名,管理者姓名(管理者外键为mgr)
selecta.enameas姓名,b.enameas管理者fromempasa,empasbwherea.mgrisnotnullanda.mgr=b.empno
10对于dept表中,列出所有部门名,部门号,同时列出各部门工作为'CLERK'的员工名与工作
selectdnameas部门名,dept.deptnoas部门号,enameas员工名,jobas工作fromdept,emp
wheredept.deptno*=emp.deptnoandjob='CLERK'
11对于工资高于本部门平均水平的员工,列出部门号,姓名,工资,按部门号排序
selecta.deptnoas部门号,a.enameas姓名,a.salas工资fromempasa
wherea.sal>(selectavg(sal)fromempasbwherea.deptno=b.deptno)orderbya.deptno
12对于emp,列出各个部门中平均工资高于本部门平均水平的员工数和部门号,按部门号排序
selectcount(a.sal)as员工数,a.deptnoas部门号fromempasa
wherea.sal>(selectavg(sal)fromempasbwherea.deptno=b.deptno)groupbya.deptnoorderbya.deptno
13对于emp中工资高于本部门平均水平,人数多与1人的,列出部门号,人数,按部门号排序
selectcount(a.empno)as员工数,a.deptnoas部门号,avg(sal)as平均工资fromempasa
where(selectcount(c.empno)fromempascwherec.deptno=a.deptnoandc.sal>(selectavg(sal)fromempasbwherec.deptno=b.deptno))>1
groupbya.deptnoorderbya.deptno
14对于emp中低于自己工资至少5人的员工,列出其部门号,姓名,工资,以及工资少于自己的人数
selecta.deptno,a.ename,a.sal,(selectcount(b.ename)fromempasbwhereb.salwhere(selectcount(b.ename)fromempasbwhereb.sal5
数据库笔试题及答案
第一套
一.选择题
1.下面叙述正确的是CCBAD______。
A、算法的执行效率与数据的存储结构无关
B、算法的空间复杂度是指算法程序中指令(或语句)的条数
C、算法的有穷性是指算法必须能在执行有限个步骤之后终止
D、以上三种描述都不对
2.以下数据结构中不属于线性数据结构的是______。
A、队列B、线性表C、二叉树D、栈
3.在一棵二叉树上第5层的结点数最多是______。
A、8B、16C、32D、15
4.下面描述中,符合结构化程序设计风格的是______。
A、使用顺序、选择和重复(循环)三种基本控制结构表示程序的控制逻辑
B、模块只有一个入口,可以有多个出口
C、注重提高程序的执行效率D、不使用goto语句
5.下面概念中,不属于面向对象方法的是______。
A、对象B、继承C、类D、过程调用
6.在结构化方法中,用数据流程图(DFD)作为描述工具的软件开发阶段是___BDBCA___。
A、可行性分析B、需求分析C、详细设计D、程序编码
7.在软件开发中,下面任务不属于设计阶段的是______。
A、数据结构设计B、给出系统模块结构C、定义模块算法D、定义需求并建立系统模型
8.数据库系统的核心是______。
A、数据模型B、数据库管理系统