资源描述:
《实验五 多表查询.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验五多表查询1.找出同一天进入公司工作的员工selectdistincta.employeeNo,a.employeeName,a.hireDatefromEmployeea,Employeebwherea.employeeNo!=b.employeeNoanda.hireDate=b.hireDate2.查找与“陈诗杰”在同一个单位工作的员工姓名,性别,部门和职务selecta.employeeName,a.sex,a.department,a.headShipfromEmployeea,Employeebwherea.depa
2、rtment=b.departmentandb.employeeName='陈诗杰'3.在employee表中查询薪水超过员工平均薪水的员工信息select*fromEmployeeawherea.salary>(selectavg(b.salary)fromEmployeeb)4.查找有销售记录的客户编号,名称和订单总额selecta.customerNo,a.customerName,b.orderNo,sum(quantity*price)orderSumfromCustomera,OrderMasterb,OrderDeta
3、ilcwherea.customerNo=b.customerNoandb.orderNo=c.orderNogroupbya.customerNo,a.customerName,b.orderNo4.查询没有订购商品的客户编号和客户名称5.使用子查询查找32MDRAM的销售情况,要求显示相应的销售员的姓名,性别,销售日期,销售数量和经济呢,其中性别用“男”和“女”表示selectemployeeName,casesexwhen'M'then'男'when'F'then'女'endassex,b.orderDate,c.quanti
4、ty销售数量,c.quantity*c.price金额fromEmployeea,OrderMasterb,OrderDetailcwherea.employeeNo=b.salerNoandb.orderNo=c.orderNoandc.productNoin(selectf.productNofromOrderMasterd,OrderDetaile,Productfwhered.orderNo=e.orderNoandproductName='32MDRAM')4.查询OrderMaster表中订单金额最高的订单号及订单金额s
5、electorderNo,sum(quantity*price)orderSumfromOrderDetailgroupbyorderNohavingsum(quantity*price)=(selectmax(orderSum)from(selectorderNo,sum(quantity*price)orderSumfromOrderDetailgroupbyorderNo)b)5.在订单主表中查询订单金额大于“E2005002业务员在2008-1-9这天所接的任一张订单的金额”的所有订单信息。select*fromOrderM
6、asterwhereorderSum>any(selectorderSumfromOrderMasterwheresalerNo='E2005002'andorderDate='2008-1-9')4.查询单价高于400元的商品编号,商品名称,订货数量和订货单价。selecta.productNo,a.productName,sum(b.quantity)订货数量,b.pricefromProducta,OrderDetailbwherea.productPrice>400andb.productNo=a.productNogrou
7、pbya.productNo,a.productName,b.price5.分别使用左外连接,右外连接,完整外部连接查询单价高于400元的商品编号,商品名称,订货数量和订货单价,并分析比较检索的结果。左外连接:selecta.productNo,a.productName,sum(b.quantity)订货数量,b.pricefromProductaleftouterjoinOrderDetailbona.productPrice>400andb.productNo=a.productNogroupbya.productNo,a.p
8、roductName,b.price右外连接:selecta.productNo,a.productName,sum(b.quantity)订货数量,b.pricefromProductarightouterjoinOrderDeta