欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    实验五数据查询-复杂查询.doc

    • 资源ID:2768775       资源大小:142KB        全文页数:11页
    • 资源格式: DOC        下载积分:8金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要8金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    实验五数据查询-复杂查询.doc

    实验五 数据查询复杂查询一、实验目的 1掌握SQLServer查询语句的基本语法2熟练使用SQL的Select语句对多表进行查询3熟练掌握并运用SQLServer所提供的函数4熟练使用SQL语句进行复杂的连接操作 二、实验环境(实验的软件、硬件环境)硬件:PC机 软件:SQL2000三、实验指导说明请复习相关的查询知识点并完成如下内容。四、实验内容1在订单数据库orderDB中,完成如下的查询:(1)用子查询查询员工“张小娟”所做的订单信息。(2)查询没有订购商品的且在北京地区的客户编号,客户名称和邮政编码,并按邮政编码降序排序。(3)查询订购了“32M DRAM”商品的订单编号,订货数量和订货单价。(4)查询与员工编号“E2008005”在同一个部门的员工编号,姓名,性别,所属部门。(5)查询既订购了P20050001商品,又订购了P20070002商品的客户编号,订单编号和订单金额(6)查询没有订购“52倍速光驱”或“17寸显示器”的客户编号,客户名称。(7)查询订单金额最高的订单编号,客户姓名,销售员名称和相应的订单金额。(8)查询订购了“52倍速光驱”商品的订购数量,订购平均价和订购总金额。(9)查询订购了“52倍速光驱”商品且订货数量界于24之间的订单编号,订货数量和订货金额。(10)在订单主表中查询每个业务员的订单数量(11)统计在业务科工作且在1973年或1967年出生的员工人数和平均工资。(12)在订单明细表中统计每种商品的销售数量和金额,并按销售金额的升序排序输出。(13)统计客户号为“C20050001”的客户的订单数,订货总额和平均订货金额(14)统计每个客户的订单数,订货总额和平均订货金额。(15)查询订单中至少包含3种(含3种)以上商品的订单编号及订购次数,且订购的商品数量在3件(含3件)以上。(16)查找订购了“32M DRAM”的商品的客户编号,客户名称,订货总数量和订货总金额。(17)查询每个客户订购的商品编号,商品所属类别,商品数量及订货金额,结果显示客户名称,商品所属类别,商品数量及订货金额,并按客户编号升序和按订货金额的降序排序输出。(18)按商品类别查询每类商品的订货平均单价在280元(含280元)以上的订货总数量,订货平均单价和订货总金额。(19)查找至少有2次销售的业务员名称和销售日期。(20)查询销售金额最大的客户名称和总货款额(21)查找销售总额小于5000元的销售员编号,姓名和销售额(22)查找至少订购了3种商品的客户编号,客户名称,商品编号,商品名称,数量和金额。(23)查找同时订购了商品为“P20070002”和商品编号为“P20070001”的商品的客户编号,客户姓名,商品编号,商品名称和销售数量,按客户编号排序输出。(24)计算每一商品每月的销售金额总和,并将结果首先按销售月份然后按订货金额降序排序输出。(25)查询订购了“键盘”商品的客户姓名,订货数量和订货日期(26)查询每月订购“键盘”商品的客户名称。(27)查询至少销售了5种商品的销售员编号,姓名,商品名称,数量及相应的单价,并按销售员编号排序输出。(28)查询没有订购商品的客户编号和客户名称。(29)查询至少包含了“世界技术开发公司”所订购的商品的客户编号,客户名称,商品编号,商品名称,数量和金额。五、实验步骤请完成实验内容,并写出具体的实验步骤(1)用子查询查询员工“张小娟”所做的订单信息。select orderMaster.* from employee ,orderMaster where orderMaster .SaleNo =employeeNo and employeeName in(select employee.employeeName from employee where employeeName =张小娟)(2)查询没有订购商品的且在北京地区的客户编号,客户名称和邮政编码,并按邮政编码降序排序。select distinct customer.CustomerNo ,customer.customerName ,customer.Zip from customer ,orderMaster where customer .customerNo not in(select orderMaster .customerNo from orderMaster )and customer.addr=北京市order by customer .Zip desc(3)查询订购了“32M DRAM”商品的订单编号,订货数量和订货单价。select orderDetail .OrderNo ,orderDetail .Qty ,orderDetail .Price from orderDetail ,product where orderDetail.ProductNo =product .ProductNo and ProductName =32M DRAM(4)查询与员工编号“E2008005”在同一个部门的员工编号,姓名,性别,所属部门。select employee .employeeNo ,employee .employeeName ,case employee.Sex when Mthen 男when Fthen 女end ,employee .Department from employee where employee.Department =(select employee .Department from employee where employee .employeeNo =E2008005)(5)查询既订购了P20050001商品,又订购了P20070002商品的客户编号,订单编号和订单金额select customer .customerno,ordermaster .orderno ,ordermaster .ordersum from ordermaster ,customer,orderdetail where customer.customerno =ordermaster .customerno and ordermaster .orderno =orderdetail .orderno and orderdetail .productno=P2007002intersectselect customer .customerno,ordermaster .orderno ,ordermaster .ordersum from ordermaster ,customer,orderdetail where customer.customerno =ordermaster .customerno and ordermaster .orderno =orderdetail .orderno and orderdetail .productno=P2005001(6)查询没有订购“52倍速光驱”或“17寸显示器”的客户编号,客户名称。select distinct customer .customerno ,customer .customername from customer ,orderdetail ,ordermaster,product where orderdetail .orderno =ordermaster .orderno and ordermaster .customerno =customer .customerno and orderdetail .productno =product .productno and product .productname not in (52倍速光驱,17寸显示器) (7)查询订单金额最高的订单编号,客户姓名,销售员名称和相应的订单金额。select ordermaster .orderno ,customer .customername ,employee .employeename ,ordermaster .ordersum from employee ,ordermaster,customer where employee .employeeno =ordermaster .saleno and customer .customerno =ordermaster .customerno and ordermaster .ordersum =(select MAX (ordermaster .ordersum )from ordermaster)(8)查询订购了“52倍速光驱”商品的订购数量,订购平均价和订购总金额。select SUM (orderdetail .qty )as订购数量,AVG (ordermaster.ordersum )as订购平均价,SUM (ordermaster .ordersum )as订购总金额 from orderdetail ,ordermaster ,product where orderdetail .orderno =ordermaster .orderno and orderdetail .productno =product .productno and product .productname =52倍速光驱(9)查询订购了“52倍速光驱”商品且订货数量界于4之间的订单编号,订货数量和订货金额。select orderdetail.orderno ,orderdetail .qty ,ordermaster .ordersum from ordermaster,orderdetail ,product whereorderdetail .orderno =ordermaster .orderno and product .productno =orderdetail.productno and product .productname =52倍速光驱and orderdetail .qty between 2 and 4(10)在订单主表中查询每个业务员的订单数量select ordermaster.saleno ,COUNT (*)as 订单数量from ordermaster group by saleno (11)统计在业务科工作且在年或年出生的员工人数和平均工资。select COUNT (*)as 员工人数,AVG (employee .salary )as 平均工资from employee(12)在订单明细表中统计每种商品的销售数量和金额,并按销售金额的升序排序输出。select orderdetail .productno ,SUM(orderdetail .qty )as 销售数量,SUM(orderdetail .price *orderdetail .qty )as 金额from orderdetail group by orderdetail .productno order by SUM(orderdetail .price *orderdetail .qty )(13)统计客户号为“C20050001”的客户的订单数,订货总额和平均订货金额select customer .customerno ,COUNT (orderdetail .orderno )as 订单数,SUM (ordermaster .ordersum )as 订货总额,AVG (ordermaster .ordersum )as 平均订单金额 from orderdetail ,ordermaster ,customer where orderdetail .orderno =ordermaster .orderno and ordermaster.customerno =customer .customerno and customer .customerno =C2005001 group by customer .customerno (14)统计每个客户的订单数,订货总额和平均订货金额。select customer .customerno ,COUNT (orderdetail .orderno )as 订单数,SUM (ordermaster .ordersum )as 订货总额,AVG (ordermaster .ordersum )as 平均订单金额 from orderdetail ,ordermaster ,customer where orderdetail .orderno =ordermaster .orderno and ordermaster.customerno =customer .customerno group by customer .customerno (15)查询订单中至少包含种(含种)以上商品的订单编号及订购次数,且订购的商品数量在件(含件)以上。select orderno ,count(*)from orderdetail where orderno in(select orderdetail.orderno from orderdetail group by orderno having COUNT(orderno)>=3) group by orderno (16)查找订购了“32M DRAM”的商品的客户编号,客户名称,订货总数量和订货总金额。select customer.customerno,customername,SUM(qty)as 订货总数量,SUM(ordermaster .ordersum)as 订货总金额from product,orderdetail,customer,ordermaster where customer .customerno =ordermaster .customerno and ordermaster .orderno=orderdetail .orderno and product.productno =orderdetail .productno and product .productname =32M DRAMgroup by customer.customerno ,customername(17)查询每个客户订购的商品编号,商品所属类别,商品数量及订货金额,结果显示客户名称,商品所属类别,商品数量及订货金额,并按客户编号升序和按订货金额的降序排序输出。select customername,product.productno,product.productclass,orderdetail .qty ,orderdetail .price *orderdetail .qty from orderdetail ,product ,customer ,ordermaster where customer.customerno =ordermaster .customerno and ordermaster .orderno =orderdetail .orderno and orderdetail .productno =product .productno order by customer.customerno asc,orderdetail .price *orderdetail .qty desc(18)按商品类别查询每类商品的订货平均单价在元(含元)以上的订货总数量,订货平均单价和订货总金额。select COUNT(qty)as订货总数量,AVG (price )as订货评价单价,SUM(ordersum )as订货总金额 from product, ordermaster a,orderdetail b where a.orderno =b.orderno and product .productno =b.productno group by product.productclass having AVG (price )>=280(19)查找至少有次销售的业务员名称和销售日期。select employee .employeename ,ordermaster .orderdate from employee ,ordermaster where employee .employeeno =ordermaster.saleno and employeeno in (select saleno from ordermaster group by saleno having COUNT (*)>=2) order by employeename (20)查询销售金额最大的客户名称和总货款额select customer.customername,max(a.b) from customer,ordermaster,(select top 1 ordermaster .customerno,SUM(ordermaster.ordersum) as b from ordermaster group by customerno )awhere customer.customerno =ordermaster.customerno and a.customerno =customer .customerno group by customername select customername,MAX(b.a) from customer,(select customerno,sum(ordersum )a from ordermaster group by customerno)b group by customername where customer .customerno =b.customerno group by customername (21)查找销售总额小于元的销售员编号,姓名和销售额select employee.employeeno,employeename,a from employee,(select saleno,SUM(ordersum) a from ordermaster group by saleno )b where b.saleno =employeeno and a<5000(22)查找至少订购了种商品的客户编号,客户名称,商品编号,商品名称,数量和金额。select customer.customerno,customer.customername,product.productno,product.productname,orderdetail.qty,orderdetail.price*orderdetail.qty as金额 from customer,product,orderdetail,ordermaster where customer.customerno=ordermaster .customerno and ordermaster.orderno =orderdetail.orderno and orderdetail .productno =product.productno and customer.customerno in (select customer.customerno from customer,product,orderdetail,ordermaster where customer.customerno=ordermaster .customerno and ordermaster.orderno =orderdetail.orderno and orderdetail .productno =product.productno group by customer.customerno having count(customer.customerno)>=3 ) order by customerno(23)查找同时订购了商品为“P20070002”和商品编号为“P20070001”的商品的客户编号,客户姓名,商品编号, 商品名称和销售数量,按客户编号排序输出。select customer.customerno,customername,product.productno ,productname,orderdetail.qty from customer,product,orderdetail,ordermaster where customer.customerno=ordermaster .customerno and ordermaster.orderno=orderdetail.orderno and orderdetail .productno =product.productno and customer.customerno in(select customer.customerno from customer,product,orderdetail,ordermaster where customer.customerno=ordermaster .customerno and ordermaster.orderno=orderdetail.orderno and orderdetail .productno =product.productno and product.productno =P2007002intersectselect customer.customerno from customer,product,orderdetail,ordermaster where customer.customerno=ordermaster .customerno and ordermaster.orderno=orderdetail.orderno and orderdetail .productno =product.productno and product.productno =P2007001) order by customer.customerno (24)计算每一商品每月的销售金额总和,并将结果首先按销售月份然后按订货金额降序排序输出。select ordermaster.customerno ,ordermaster .orderdate,sum(ordersum) as 销售金额总和 from ordermaster group by ordermaster .customerno,ordermaster.orderdate order by ordermaster .orderdate,销售金额总和 desc(25)查询订购了“键盘”商品的客户姓名,订货数量和订货日期select customer.customername,orderdetail.qty,ordermaster .orderdate from customer,orderdetail,ordermaster,product where customer.customerno=ordermaster .customerno and orderdetail .orderno =ordermaster .orderno andproduct.productno =orderdetail .productno and productname=键盘(26)查询没有订购“键盘”商品的客户名称。select distinct customername from customer where customername not in(select distinct customername from customer,ordermaster,orderdetail,product whereordermaster .customerno =customer.customerno and ordermaster .orderno =orderdetail .orderno and product.productno =orderdetail.productno and productname=键盘)(27)查询至少销售了种商品的销售员编号,姓名,商品名称,数量及相应的单价,并按销售员编号排序输出。select employee.employeeno,employeename,productname,orderdetail.qty,orderdetail .price from employee,product,orderdetail,ordermaster where employee.employeeno =ordermaster.saleno and ordermaster.orderno =orderdetail.orderno and orderdetail.productno =product .productno and employee.employeeno in(select employee.employeeno from employee,product,orderdetail,ordermaster where employee.employeeno =ordermaster.saleno and ordermaster.orderno =orderdetail.orderno and orderdetail.productno =product .productno group by employee .employeeno having COUNT(employee.employeeno)>=5)order by employeeno (28)查询没有订购商品的客户编号和客户名称。select a.customerno from customer a where not exists(select *from ordermaster where a.customerno =ordermaster.customerno)(29)查询至少包含了“世界技术开发公司”所订购的商品的客户编号,客户名称,商品编号,商品名称,数量和金额。select customer.customerno ,customername,product.productno ,productname,orderdetail .qty ,qty*price from customer,product ,orderdetail ,ordermaster where customer.customerno =ordermaster .customerno and ordermaster .orderno =orderdetail .orderno and orderdetail .productno =product.productno and customer .customername in(select customername from customer where not exists(select *from (select customername,orderdetail .productno from customer custoemrb,orderdetail ,ordermaster ,product productb where custoemrb.customername =世界技术开发公司and custoemrb .customerno =ordermaster .customerno and ordermaster .orderno =orderdetail .orderno and orderdetail .productno =productb.productno)a where not exists (select *from (select customername,orderdetail .productno from customer custoemrb,orderdetail ,ordermaster ,product productb where custoemrb .customerno =ordermaster .customerno and ordermaster .orderno =orderdetail .orderno and orderdetail .productno =productb.productno) bwhere customer.customername =b.customername and b.productno =a.productno )六、思考题:1存在量词与集合运算in、连接运算和全程量词之间的关系如何?他们可以互相替换吗?给出你的理由2Where子句和having子句都是用于指定查询条件的,请区别它们的异同?用实例说明。3在分组聚集操作中,为什么在查询列中,除了聚集函数运算外,其它表达式必须包含在group by子句中?七、总结(实验过程的体会、心得和实验教与学之间还需改进的内容)

    注意事项

    本文(实验五数据查询-复杂查询.doc)为本站会员(小**)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开