资源描述:
《实验五-复杂查询-实验报告》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验五复杂查询1实验目的与要求(1)熟练掌握SQL语句的使用。(2)熟练使用SQL语句进行连接操作。2实验内容(1)在订单明细表中查询订单金额最高的订单。selecta.*fromorderdetaila,ordermasterbwherea.orderno=b.ordernoandordersum=(selectmax(ordersum)fromordermaster)(2)找出至少被订购3次的商品编号、订单编号、订货数量和订货金额,并按订货数量的降序排序输出。selectproductno商品编号,orderno订单编号,quantity订货数量,qua
2、ntity*price订货金额fromorderdetailwhereproductnoin(selectproductnofromorderdetailgroupbyproductnohavingcount(*)>=3)orderbyquantitydesc8(1)查找销售总额少于5000元的销售员编号、姓名和销售额。selecta.salerno销售员编号,b.employeename姓名,sum(ordersum)销售额fromordermastera,employeebwherea.salerno=b.employeenogroupbya.saler
3、no,b.employeenamehavingsum(ordersum)<5000(2)找出目前业绩未超过5000元的员工,并按销售业绩的降序排序输出。selectsalerno销售员编号,sum(ordersum)销售业绩fromordermastergroupbysalernohavingsum(ordersum)<=5000orderbysum(ordersum)desc(3)查询订购的商品数量没有超过10个的客户编号和客户名称。selecta.customerno客户编号,customername客户名称fromcustomera,ordermast
4、erb,orderdetailcwherea.customerno=b.customernoandb.orderno=c.ordernogroupbya.customerno,customernamehavingsum(quantity)<=108(1)查找订货金额最大的客户名称和总货款。selectcustomerno客户名称,sum(ordersum)总货款fromordermastergroupbycustomernohavingsum(ordersum)=(selectmax(sumorder)from(selectcustomerno,sum(or
5、dersum)assumorderfromordermastergroupbycustomerno)b)(2)查找至少订购了3种商品的客户编号、客户名称、商品编号、商品名称、数量和金额。selecta.customerno客户编号,customername客户名称,b.productno商品编号,productname商品名称,quantity数量,quantity*price金额fromcustomera,productb,ordermasterc,orderdetaildwherea.customerno=c.customernoandb.product
6、no=d.productnoandc.orderno=d.ordernoandd.ordernoin(selectordernofromorderdetailgroupbyordernohavingcount(productno)>=3)orderbya.customerno8(1)找出目前销售业绩超过4000元的业务员编号及销售业绩,并按销售业绩从大到小排序。selectsalerno销售员编号,sum(ordersum)销售业绩fromordermastergroupbysalernohavingsum(ordersum)>4000orderbysum(
7、ordersum)desc(2)求每位客户订购的每种商品的总数量及平均单价,并按客户号、商品号从小到大排列。selectcustomerno客户编号,productno商品编号,sum(quantity)总数量,avg(price)平均单价fromordermastera,orderdetailbwherea.orderno=b.ordernogroupbycustomerno,productnoorderbycustomerno,productno(3)查询业绩最好的的业务员号、业务员名及其总销售金额。selectsalerno业务员号,employeen
8、ame业务员名,sum(ordersum)销售金额f