实验五 多表查询.doc_第1页
实验五 多表查询.doc_第2页
实验五 多表查询.doc_第3页
实验五 多表查询.doc_第4页
实验五 多表查询.doc_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验五 多表查询1.找出同一天进入公司工作的员工select distinct a.employeeNo,a.employeeName,a.hireDatefrom Employee a,Employee bwhere a.employeeNo!=b.employeeNo and a.hireDate=b.hireDate2.查找与“陈诗杰”在同一个单位工作的员工姓名,性别,部门和职务select a.employeeName,a.sex,a.department,a.headShipfrom Employee a,Employee bwhere a.department=b.department and b.employeeName=陈诗杰3.在employee表中查询薪水超过员工平均薪水的员工信息select *from Employee awhere a.salary(select avg(b.salary)from Employee b)4. 查找有销售记录的客户编号,名称和订单总额select a.customerNo,a.customerName,b.orderNo,sum(quantity*price) orderSumfrom Customer a,OrderMaster b,OrderDetail cwhere a.customerNo=b.customerNo and b.orderNo=c.orderNogroup by a.customerNo,a.customerName,b.orderNo5. 查询没有订购商品的客户编号和客户名称6. 使用子查询查找32M DRAM的销售情况,要求显示相应的销售员的姓名,性别,销售日期,销售数量和经济呢,其中性别用“男”和“女”表示select employeeName,case sexwhen M then 男when F then 女end as sex,b.orderDate,c.quantity 销售数量,c.quantity*c.price 金额from Employee a,OrderMaster b,OrderDetail cwhere a.employeeNo=b.salerNo and b.orderNo=c.orderNo and ductNo in(select ductNofrom OrderMaster d,OrderDetail e,Product fwhere d.orderNo=e.orderNo and productName=32M DRAM)7. 查询OrderMaster表中订单金额最高的订单号及订单金额select orderNo,sum(quantity*price) orderSumfrom OrderDetailgroup by orderNohaving sum(quantity*price)=(select max(orderSum)from (select orderNo,sum(quantity*price) orderSumfrom OrderDetailgroup by orderNo)b)8. 在订单主表中查询订单金额大于“E2005002业务员在2008-1-9这天所接的任一张订单的金额”的所有订单信息。select *from OrderMasterwhere orderSumany(select orderSum from OrderMaster where salerNo=E2005002 and orderDate=2008-1-9)9. 查询单价高于400元的商品编号,商品名称,订货数量和订货单价。select ductNo,ductName,sum(b.quantity)订货数量,b.pricefrom Product a,OrderDetail bwhere ductPrice400 and ductNo=ductNogroup by ductNo,ductName,b.price10. 分别使用左外连接,右外连接,完整外部连接查询单价高于400元的商品编号,商品名称,订货数量和订货单价,并分析比较检索的结果。左外连接:select ductNo,ductName,sum(b.quantity)订货数量,b.pricefrom Product a left outer join OrderDetail b on ductPrice400 and ductNo=ductNogroup by ductNo,ductName,b.price右外连接:select ductNo,ductName,sum(b.quantity)订货数量,b.pricefrom Product a right outer join OrderDetail b on ductPrice400 and ductNo=ductNogroup by ductNo,ductName,b.price全外连接:select ductNo,ductName,sum(b.quantity)订货数量,b.pricefrom Product a full outer join OrderDetail b on ductPrice400 and ductNo=ductNogroup by ductNo,ductName,b.price11. 使用左外连接查找每个客户的客户编号,名称,订货日期,订单金额,其中订货日期不显示时间,日期格式为yyyy-mm-dd,按客户编号排序,同一客户再按订单金额降序排序输出。select a.customerno 客户编号,customername 客户名称,convert(char(10),orderdate,120)销售日期,ordersum 销售金额from ordermaster a left outer join customer b on (a.customerno=b.customerno)order by a.customerno,ordersum desc12. 查找每个员工的销售记录,要求显示销售员的编号、姓名、性别、商品名称、数量、单价、金额和销售日期,其中性别使用“男”和“女”表示,日期使用yyyy-mm-dd格式显示。select a.employeeNo,a.employeeName,case sexwhenFthen女whenMthen男Endsex,ductName,d.quantity,d.price,d.quantity*d.price 金额,orderDate=convert(char(10),orderDate,120)from Employee a,Product b,OrderMaster c,OrderDetail dwhere a.employeeNo=c.salerNo and ductNo=ductNo and c.orderNo=d.orderNo13. 查询32M DRAM的销售情况,要求显示相应的销售员的姓名,性别,销售日期,销售数量和金额,其中性别用“男”,“女”表示。select a.employeeName,case sexwhenFthen女whenMthen男end as sex,b.orderDate,c.quantity,c.price*c.quantity 金额from Employee a,OrderMaster b,OrderDetail c,Product dwhere a.employeeNo=b.salerNo and b.orderNo=c.orderNo and ductNo=ductNo and ductName=32M DRAM14. 找出公司男业务员所接且订单金额超过2000的订单号及订单金额。select b.orderNo,b.orderSumfrom Employee a,OrderMaster bwhere a.employeeNo=b.salerNo and sex=M and b.orderSum200015. 查询每种商品的总销售数量及总销售金额,要求显示出商品编号,商品名称,总数量及总金额,并按商品号从小到大排列。select ductno 商品编号,productname 商品名称,sum(quantity)总销售数量,sum(quantity*price) 总销售金额from product a,orderdetail bwhere ductno=ductno group by ductno,productnameorder by ductno16.实验问题:有哪些连接操作类型?分析外连接在现实应用的意义。有等值连接,非等值连接,自然连接,自表链接,外连接(左外联接,右外连接,全外连接)等等;实践中需要把不满足连接条件的元祖检索出来,外连接则可以实现这样的查询查询表可以用在什么地方?使用查询要注意什么?可以放在from子句,where子句后面,使用查询表需要注意查询条件,并且在必要时为查询表设置一个元组变量名,用该

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论