资源预览内容
第1页 / 共14页
第2页 / 共14页
第3页 / 共14页
第4页 / 共14页
第5页 / 共14页
第6页 / 共14页
第7页 / 共14页
第8页 / 共14页
第9页 / 共14页
第10页 / 共14页
亲,该文档总共14页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
实验一 简单查询在订单数据库中,完成如下的查询:(1) 查询所有业务部门的员工姓名、职称、薪水。select employeeName,headShip,salaryfrom employeewhere department=业务科(2) 查询名字中含有“有限”的客户姓名和所在地。select CustomerName,addressfrom Customerwhere CustomerName like %有限%(3) 查询出姓“王”并且姓名的最后一个字为“成”的员工。select *from employeewhere employeeName like 王%成没有结果(4) 查询住址中含有上海或南昌的女员工,并显示其姓名、所属部门、职称、住址,其中性别用“男”和“女”显示。select employeeName,department,headship,address,sex= Case sex when Mthen 男 when Fthen 女 endfrom employeewhere address like%上海% or address like %南昌% and sex=F(5) 在订单明细表OrderDetail中挑出销售金额大于等于10000元的订单。select orderNofrom OrderDetailgroup by orderNohaving sum(quantity*price)=10000 (6) 选取订单金额最高的前10%的订单数据。SELECT TOP 10 PERCENT orderNoFROM OrderdetailGROUP BY orderNoORDER BY sum(quantity*price) DESC(7) 查询出职务为“职员”或职务为“科长”的女员工的信息。select *from employeewhere (headship=职员 or headship=科长) and sex=F(8) 查找定单金额高于8000的所有客户编号。 1)查询总金额高于8000元的客户编号select CustomerNofrom OrderMaster a,Orderdetail bwhere a.orderNo=b.orderNogroup by CustomerNohaving sum(quantity*price)8000 2)查找定单金额高于8000的所有客户编号 select CustomerNofrom OrderMaster where orderNo in ( select orderNo from OrderDetail group by orderNo having sum(quantity*price)8000 )(9) 选取编号界于“C”和“C”的客户编号、客户名称、客户地址。select CustomerNo,CustomerName,addressfrom Customerwhere CustomerNo between C and C(11) 找出同一天进入公司服务的员工。Select a.employeeNo,a.employeeName,b.employeeNo,b.employeeNamefrom Employee a,Employee as bwhere a.employeeNo!=b.employeeNo and a.employeeNameb.employeeName and (a.hireDate=b.hireDate)(12) 在订单主表中查询订单金额大于“E业务员在2008-1-9这天所接的任一张订单的金额”的所有订单信息。 1)首先计算订单主表的订单金额 update OrderMaster set orderSum=totalSumfrom OrderMaster a,(select orderNo,sum(quantity*price) totalSum from OrderDetail group by orderNo) bwhere a.orderNO=b.orderNo 2)SELECT *FROM OrderMasterWHERE orderSumany (SELECT orderSum FROM OrderMaster WHERE salerNo=E AND orderDate= )(13) 查询既订购了“52倍速光驱”商品,又订购了“17寸显示器”商品的客户编号、订单编号和订单金额。Select customerNo,orderNo,orderSumfrom OrderMaster where customerNo in (select customerNo from OrderMaster a,OrderDetail b,Product c where a.orderNo=b.orderNo and b.productNo=c.productNo and productName=52倍速光驱) and customerNo in (select customerNo from OrderMaster a,OrderDetail b,Product c where a.orderNo=b.orderNo and b.productNo=c.productNo and productName=17寸显示器) (14) 查找与“陈诗杰”在同一个单位工作的员工姓名、性别、部门和职务。Select b.employeeName,b.sex,b.department,b.headShipfrom Employee a,Employee bwhere a.department=b.department and a.employeeName=陈诗杰(15) 查询每种商品的商品编号、商品名称、订货数量和订货单价。SELECT a.productNo,productName,quantity,priceFROM Product a, OrderDetail bWHERE a.productNo=b.productNoORDER BY productName,price(16) 查询单价高于400元的商品编号、商品名称、订货数量和订货单价。SELECT a.productNo,productName,quantity,priceFROM Product a, OrderDetail bWHERE a.productNo=b.productNo AND price400ORDER BY productName(17) 分别使用左外连接、右外连接、完整外部连接查询单价高于400元的商品编号、商品名称、订货数量和订货单价,并分析比较检索的结果。左外连接命令:SELECT a.productNo,productName,quantity,priceFROM Product a LEFT OUTER JOIN OrderDetail b ON a.productNo=b.productNoWHERE price400Select a.productNo , a.productName , b.quantity,b.priceFrom OrderDetail As b left JOIN Product As a ON (a.productNo=b.productNo) and price400Order by a.productNo右外连接命令:SELECT a.productNo,productName,quantity,priceFROM Product a RIGHT OUTER JOIN OrderDetail b ON a.productNo=b.productNoWHERE price400Select a.productNo , a.productName , b.quantity,b.priceFrom OrderDetail As b RIGHT JOIN Product As a ON (a.productNo=b.productNo) and price400Order by a.productNo全连接命令:SELECT a.productNo,productName,quantity,priceFROM Product a FULL OUTER JOIN OrderDetail b ON a.productNo=b.productNoWHERE price400Select a.productNo , a.productName , b.quantity,b.priceFrom OrderDetail As b full JOIN Product As a ON (a.productNo=b.productNo) and price400Order by a.productNo(18)分别使用左外连接、右外连接、完整外部连接查询客户编号、客户名称、订货金额和订单编号,并分析比较检索的结果。SELECT a.customerNo,customerName,orderSum,orderNoFROM Customer a left OUTER JOIN OrderMaster b ON a.customerNo=b.customerNoSELECT a.customerNo,customerName,orderSum,orderNoFROM Customer a right OUTER JOIN OrderMaster b ON a.customerNo=b.customerNoSELECT a.customerNo,customerName,orderSum,orderNoFROM Customer a full OUTER JOIN OrderMaster b ON a.customerNo=b.customerNo从上述结果可知:若表a和表b做外连接,且b表是外码表,则a和b表左外连接可能会出现空值,但是右连接一定不会出现空值,全外连接与左外连接一样的结果。 (18) 查找每个员工的销售记录,要求显示销售员的编号、姓名、性别、商品名称、数量、单价、金额和销售日期,其中性别使用“男”和“
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号