数据库期中复习题及部分答案.doc

上传人:pu****.1 文档编号:556182560 上传时间:2023-03-16 格式:DOC 页数:12 大小:116.50KB
返回 下载 相关 举报
数据库期中复习题及部分答案.doc_第1页
第1页 / 共12页
数据库期中复习题及部分答案.doc_第2页
第2页 / 共12页
数据库期中复习题及部分答案.doc_第3页
第3页 / 共12页
数据库期中复习题及部分答案.doc_第4页
第4页 / 共12页
数据库期中复习题及部分答案.doc_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《数据库期中复习题及部分答案.doc》由会员分享,可在线阅读,更多相关《数据库期中复习题及部分答案.doc(12页珍藏版)》请在金锄头文库上搜索。

1、1、查找表中所有姓刘的职工的工号,部门,薪水selectemp_no,emp_name,dept,salaryfromemployeewhereemp_name like 刘% 2、查找所有定单金额高于20000的所有客户编号selectcust_idfrom saleswheretot_amt20000 3、查找出职称为经理和职称为职员的女员工的姓名、职称、性别。selectemp_name,title,sexfromemployeewheretitle=经理ortitle=职员and sex=F4、选取销售数量最多的前5条订单订单号、数量。select top5 with tiesorde

2、r_no,sup_id,qtyfromsale_itemorder byqty desc5、按部门进行汇总,统计每个部门的总工资selectdept,sum(salary)fromemployeegroup bydept6、由employee表中查找出薪水最高的员工信息。select *fromemployeewheresalary= (selectmax(salary ) fromemployee )7、由sales表中查找出订单金额大于“E0013业务员在1996/10/15这天所接每一张订单的金额”的所有订单。select *from saleswheretot_amtall (sele

3、cttot_amt fromsales wheresale_id=E0013andorder_date=1996/10/15)order bytot_amt8、 检索product 表和sale_item表中数量大于2的相同产品的产品编号、产品名称、数量、单价。selecta.prod_id,a.qty,a.unit_price,b.prod_namefromsale_item as a innerjoin product as b /*如果改成leftjoin/rightjoin 试分析结果*/on (a.prod_id=b.pro_id)anda.qty2order bya.prod_id

4、9、查找出employee表中住址相同的员工的姓名、性别、职称、薪水、住址。selecta.emp_name,a.sex,a.title,a.salary,a.addr,b.emp_name,b.sex,b.title,b.salary,b.addrfromemployee as a innerjoin employee as bon(a.emp_no!=b.emp_no) and(a.emp_nameb.emp_name) and (a.addr=b.addr)10、查找所有经理的姓名、职称、薪水。selectemp_name,title,salaryfromemployeewheretit

5、le=经理11、查找出姓“王”并且姓名的最后一个字为“功”的员工。select*fromemployeewhereemp_namelike 王%功12、查找住在上海或北京的女员工,并显示其姓名、所属部门、职称、住址。 selectemp_name,dept title,addrfromemployeewheresex=Fand (addr like 北京% or addr like 上海%) 13、在表sales中挑出销售金额大于等于10000元订单。select*from saleswheretot_amt=10000 14、选取订单金额最高的前10%的订单数据。selecttop10 pe

6、rcent *fromsalesorderbytot_amt desc 15、查找出职称为经理或职称为职员的女员工的信息。select*from employeewheresex=Fand ( title=经理 or title=职员) 16、删除sales表中作废的订单(其发票号码为I000000004)。deletefromsale_itemwhereorder_noin (select order_nofrom saleswhereinvoice_no=I000000004) 17、计算出一共销售了几种产品。selectcount(distinctprod_id)fromsale_ite

7、m 18、显示sale_item表中每种产品的订购金额总和,并且依据销售金额由大到小排列来显示出每一种产品的排行榜。selectprod_id,sum(unit_price*qty)fromsale_itemgroupbyprod_idorderbysum(unit_price*qty) desc 19、计算每一产品每月的销售金额总和,并将结果按销售(月份,产品编号)排序。selectprod_id,month(order_date),sum(unit_price*qty)fromsale_itemgroupbyprod_id,month(order_date)orderbyprod_id,m

8、onth(order_date) selectprod_id,month(order_date),sum(unit_price*qty)fromsale_itemgroupby prod_id,month(order_date)orderby month(order_date),prod_id 20、由sales表中查找出销售金额最高的订单。select*fromsaleswheretot_amt= (select max(tot_amt) from sales) 21、由sales表中查找出订单金额大于“E0013业务员在1996/10/15这天所接任一张订单的金额”的所有订单,并显示承接这

9、些订单的业务员和该条订单的金额。selectsale_id,tot_amtfromsaleswheretot_amt all (select tot_amt from sales where sale_id=E0013 and order_date=1996-10-15) 22、找出公司女业务员所接的订单。select*fromsaleswheresale_idin (select emp_no from employee where sex=f) 23、找出公司中姓名相同的员工,并且依据员工编号排序相识这些员工信息。select*fromemployeeawhereexists (selec

10、t emp_name from employee b where a.emp_name=b.emp_name and a.emp_no b.emp_no)orderbyemp_name 24、找出目前业绩未超过2000元的员工。select*fromemployeewhereemp_noin (select sale_id from sales group by sale_id having sum(tot_amt)2000) 25、计算公司内各个部门的工资支出总和。selectdept,sum(salary)fromemployeegroupbydept 26、计算每一产品销售数量总和与平均

11、销售单价。selectprod_id,sum(unit_price*qty),avg(unit_price*qty)fromsale_itemgroupbyprod_id 27、查找出employee表中部门相同且住址相同的女员工的姓名、性别、职称、薪水、住址。Selecta.emp_name,a.sex,a.title,a.salary,a.addrfromemployeeas a inner join employee as b on(a.dept=b.dept)and(a.addr=b.addr)wherea.sex=Fandb.sex=F and a.emp_nob.emp_no Se

12、lecta.emp_name,a.sex,a.title,a.salary,a.addrfromemployee a , employee bwhere(a.dept=b.dept) and (a.addr=b.addr) anda.sex=Fand b.sex=F anda.emp_nob.emp_no28、检索product 表和sale_item表中相同产品的产品编号、产品名称、数量、单价。selecta.prod_id,b.prod_name,a.qty,a.unit_pricefromsale_itema, product bwherea.prod_id=b.prod_id /*将连

13、接设为右连接*/selecta.prod_id,b.prod_name,a.qty,a.unit_pricefromsale_itema, product bwherea.prod_id=* b.prod_id selecta.prod_id,b.prod_name,a.qty,a.unit_pricefromsale_itemas a right outer join product as bon(a.prod_id=b.prod_id) 29、检索product 表和sale_item表中单价高于2400元的相同产品的产品编号、产品名称、数量、单价。selectproduct.prod_i

14、d,product.prod_name,qty,unit_pricefromproduct,sale_itemwhere unit_price2400 andproduct.prod_id=sale_item.prod_idorderbysale_item.prod_id30、查找员工的编号、姓名、部门和出生日期,如果出生日期为空值,-显示日期不详,并按部门排序输出,日期格式为yyyy-mm-dd。selectemp_no ,emp_name ,dept ,isnull(convert(char(10),birthday,120),日期不详) birthdayfromemployeeorder

15、by dept31、查找与喻自强在同一个单位的员工姓名、性别、部门和职称selectemp_no,emp_name,dept,titlefromemployeewhereemp_name喻自强 and dept in(selectdept from employeewhereemp_name=喻自强)32、按部门进行汇总,统计每个部门的总工资selectdept,sum(salary)fromemployeegroupby dept33、查找商品名称为14寸显示器商品的销售情况,-显示该商品的编号、销售数量、单价和金额selecta.prod_id,qty,unit_price,unit_price*qty totpricefromsale_i

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

当前位置:首页 > 生活休闲 > 社会民生

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