2022年实验五数据查询——复杂查询资料 .pdf
《2022年实验五数据查询——复杂查询资料 .pdf》由会员分享,可在线阅读,更多相关《2022年实验五数据查询——复杂查询资料 .pdf(11页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、数据库原理实验学号: 123012008xxx 姓名: xxx 班级( x)小班日期: 2010 年月日1 实验五数据查询复杂查询一、实验目的1掌握 SQLServer查询语句的基本语法2熟练使用 SQL 的 Select语句对多表进行查询3熟练掌握并运用SQLServer所提供的函数4熟练使用 SQL 语句进行复杂的连接操作二、实验环境(实验的软件、硬件环境)硬件: PC机 软件: SQL2000三、实验指导说明请复习相关的查询知识点并完成如下内容。四、实验内容1在订单数据库orderDB 中,完成如下的查询:(1)用子查询查询员工“张小娟”所做的订单信息。(2)查询没有订购商品的且在北京地
2、区的客户编号,客户名称和邮政编码,并按邮政编码降序排序。(3)查询订购了“ 32M DRAM ”商品的订单编号,订货数量和订货单价。(4)查询与员工编号“ E2008005”在同一个部门的员工编号,姓名,性别,所属部门。(5)查询既订购了 P20050001商品,又订购了 P20070002商品的客户编号,订单编号和订单金额(6)查询没有订购“ 52 倍速光驱”或“ 17寸显示器”的客户编号,客户名称。(7)查询订单金额最高的订单编号,客户姓名,销售员名称和相应的订单金额。(8)查询订购了“ 52 倍速光驱”商品的订购数量,订购平均价和订购总金额。名师资料总结 - - -精品资料欢迎下载 -
3、- - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 11 页 - - - - - - - - - 数据库原理实验学号: 123012008xxx 姓名: xxx 班级( x)小班日期: 2010 年月日2 (9)查询订购了“52 倍速光驱” 商品且订货数量界于24 之间的订单编号,订货数量和订货金额。(10)在订单主表中查询每个业务员的订单数量(11) 统计在业务科工作且在1973年或 1967 年出生的员工人数和平均工资。(12)在订单明细表中统计每种商品的销售数量和金额,并按销售金额的升序排序输出。(13)统计客户号
4、为“ C20050001”的客户的订单数,订货总额和平均订货金额(14)统计每个客户的订单数,订货总额和平均订货金额。(15)查询订单中至少包含3 种(含 3 种)以上商品的订单编号及订购次数,且订购的商品数量在3 件(含 3 件)以上。(16)查找订购了“ 32M DRAM ”的商品的客户编号,客户名称,订货总数量和订货总金额。(17)查询每个客户订购的商品编号, 商品所属类别, 商品数量及订货金额,结果显示客户名称, 商品所属类别, 商品数量及订货金额, 并按客户编号升序和按订货金额的降序排序输出。(18)按商品类别查询每类商品的订货平均单价在280元(含 280元)以上的订货总数量,订货
5、平均单价和订货总金额。(19)查找至少有 2 次销售的业务员名称和销售日期。(20)查询销售金额最大的客户名称和总货款额(21)查找销售总额小于5000元的销售员编号,姓名和销售额(22)查找至少订购了3 种商品的客户编号,客户名称,商品编号,商品名称,数量和金额。(23)查找同时订购了商品为“ P20070002 ”和商品编号为“ P20070001 ”的商品的客户编号,客户姓名,商品编号,商品名称和销售数量,按客户编号排序输出。(24)计算每一商品每月的销售金额总和,并将结果首先按销售月份然后按订货金额降序排序输出。(25)查询订购了“键盘”商品的客户姓名,订货数量和订货日期名师资料总结
6、- - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 11 页 - - - - - - - - - 数据库原理实验学号: 123012008xxx 姓名: xxx 班级( x)小班日期: 2010 年月日3 (26)查询每月订购“键盘”商品的客户名称。(27)查询至少销售了5 种商品的销售员编号,姓名,商品名称,数量及相应的单价,并按销售员编号排序输出。(28)查询没有订购商品的客户编号和客户名称。(29)查询至少包含了“世界技术开发公司”所订购的商品的客户编号,客户名称,商品编号,商品名称
7、,数量和金额。五、实验步骤请完成实验内容,并写出具体的实验步骤(1)用子查询查询员工 “ 张小娟 ” 所做的订单信息 。selectorderMaster.* from employee ,orderMaster where orderMaster .SaleNo=employeeNo andemployeeNamein (selectemployee.employeeNamefrom employee whereemployeeName =张小娟) (2)查询没有订购商品的且在北京地区的客户编号,客户名称和邮政编码,并按邮政编码降序排序。selectdistinct customer.Cus
8、tomerNo ,customer.customerName,customer.Zipfrom customer ,orderMaster wherecustomer . customerNonot in(selectorderMaster .customerNo from orderMaster )andcustomer.addr=北京市 order by customer .Zip desc (3)查询订购了 “ 32M DRAM ” 商品的订单编号 ,订货数量和订货单价。selectorderDetail .OrderNo ,orderDetail .Qty ,orderDetail .
9、PricefromorderDetail ,product where orderDetail.ProductNo=product .ProductNo andProductName =32M DRAM (4)查询与员工编号 “ E2008005” 在同一个部门的员工编号,姓名 ,性别 ,所属部门 。selectemployee.employeeNo ,employee.employeeName ,caseemployee.Sex名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页
10、,共 11 页 - - - - - - - - - 数据库原理实验学号: 123012008xxx 姓名: xxx 班级( x)小班日期: 2010 年月日4 when Mthen 男when Fthen 女end, employee.Department from employeewhere employee.Department =(selectemployee.Department from employeewhereemployee.employeeNo =E2008005) (5)查询既订购了P20050001 商品,又订购了 P20070002 商品的客户编号,订单编号和订单金额s
11、electcustomer.customerno,ordermaster.orderno ,ordermaster.ordersum fromordermaster,customer,orderdetail where customer.customerno=ordermaster.customernoandordermaster.orderno =orderdetail .orderno andorderdetail .productno=P2007002 intersect selectcustomer.customerno,ordermaster.orderno ,ordermaster
12、.ordersum fromordermaster,customer,orderdetail where customer.customerno=ordermaster.customernoandordermaster.orderno =orderdetail .orderno andorderdetail .productno=P2005001 (6)查询没有订购 “ 52 倍速光驱 ” 或“ 17 寸显示器 ” 的客户编号 ,客户名称 。selectdistinct customer .customerno,customer .customernamefromcustomer ,order
13、detail ,ordermaster,productwhere orderdetail .orderno=ordermaster.orderno and ordermaster.customerno=customer .customernoandorderdetail .productno =product .productno andproduct .productname notin (52 倍速光驱 ,17 寸显示器 )(7)查询订单金额最高的订单编号,客户姓名 ,销售员名称和相应的订单金额 。selectordermaster.orderno ,customer.customerna
14、me,employee.employeename,ordermaster.ordersum from employee,ordermaster,customerwhereemployee.employeeno=ordermaster.salenoand customer.customerno=ordermaster.customernoandordermaster.ordersum =(selectMAX(ordermaster.ordersum)from ordermaster) (8)查询订购了 “ 52 倍速光驱 ” 商品的订购数量 ,订购平均价和订购总金额。名师资料总结 - - -精品
15、资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 11 页 - - - - - - - - - 数据库原理实验学号: 123012008xxx 姓名: xxx 班级( x)小班日期: 2010 年月日5 selectSUM (orderdetail .qty )as订购数量 ,AVG (ordermaster .ordersum )as订购平均价 ,SUM (ordermaster .ordersum )as订购总金额 fromorderdetail ,ordermaster,product wher
16、e orderdetail .orderno=ordermaster.orderno and orderdetail .productno =product .productno andproduct .productname =52 倍速光驱 (9)查询订购了 “ 52 倍速光驱 ” 商品且订货数量界于4 之间的订单编号 ,订货数量和订货金额。selectorderdetail.orderno ,orderdetail .qty ,ordermaster.ordersum fromordermaster,orderdetail ,product where orderdetail .orde
17、rno =ordermaster.orderno andproduct .productno=orderdetail.productno andproduct .productname =52 倍速光驱 andorderdetail .qty between 2 and 4 (10)在订单主表中查询每个业务员的订单数量selectordermaster.saleno,COUNT (*) as订单数量 from ordermastergroup bysaleno(11)统计在业务科工作且在年或年出生的员工人数和平均工资。selectCOUNT (*) as员工人数 ,AVG (employee.
18、salary )as平均工资 fromemployee (12)在订单明细表中统计每种商品的销售数量和金额,并按销售金额的升序排序输出 。selectorderdetail .productno ,SUM(orderdetail .qty )as销售数量,SUM(orderdetail .price *orderdetail .qty )as金额from orderdetail group byorderdetail .productno order by SUM(orderdetail .price *orderdetail .qty ) (13)统计客户号为 “ C20050001” 的客
19、户的订单数 ,订货总额和平均订货名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 11 页 - - - - - - - - - 数据库原理实验学号: 123012008xxx 姓名: xxx 班级( x)小班日期: 2010 年月日6 金额selectcustomer.customerno,COUNT (orderdetail .orderno )as订单数 ,SUM(ordermaster.ordersum)as订货总额 ,AVG (ordermaster.ordersu
20、m)as平均订单金额 from orderdetail ,ordermaster,customer where orderdetail .orderno=ordermaster.orderno and ordermaster .customerno=customer .customernoandcustomer .customerno=C2005001 group by customer.customerno(14)统计每个客户的订单数,订货总额和平均订货金额。selectcustomer.customerno,COUNT (orderdetail .orderno )as订单数 ,SUM(o
21、rdermaster.ordersum)as订货总额 ,AVG (ordermaster.ordersum)as平均订单金额 from orderdetail ,ordermaster,customer where orderdetail .orderno=ordermaster.orderno and ordermaster .customerno=customer .customernogroup by customer .customerno(15)查询订单中至少包含种(含种 )以上商品的订单编号及订购次数,且订购的商品数量在件(含件 )以上 。selectorderno ,count(
22、*) from orderdetail where orderno in(selectorderdetail.ordernofrom orderdetail group by orderno having COUNT (orderno)=3) group byorderno(16)查找订购了 “ 32M DRAM ” 的商品的客户编号,客户名称 ,订货总数量和订货总金额 。selectcustomer.customerno,customername,SUM(qty)as订货总数量,SUM(ordermaster.ordersum)as订货总金额 from product,orderdetail
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年实验五数据查询复杂查询资料 2022 实验 数据 查询 复杂 资料
限制150内