实验四-多表查询-实验报告

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验四多表查询

1 实验目的与要求

(1) 熟练掌握SQL语句的使用。

(2) 熟练使用SQL语句进行连接操作。

2 实验内容

(1)找出同一天进入公司服务的员工。

实验脚本:

Select

a.employeeNo,a.employeeName,a.hireDate,

b.employeeNo,b.empl

oyeeName,b.hireDate

from Employee a,Employee as b

where a.employeeNo!=b.employeeNo and

a.employeeName>

b.employeeName

and(a.hireDate=b.hireDate)

实验结果:

(2)查找与“陈诗杰”在同一个单位工作的员工姓名、性别、部门和职务。

实验脚本:

select employeeName,sex,department,headShip

from Employee

where department in(

select department

from Employee

where employeeName='陈诗杰')

实验结果:

(3)在Employee表中查询薪水超过员工平均薪水的员工信息。

实验脚本:

select*

from Employee

where salary>(

select avg(salary)

from Employee)

实验结果:

(4)查找有销售记录的客户编号、名称和订单总额。

实验脚本:

select a.customerno 客户编号,b.customerName 客户名

称,sum(a.ordersum)订单总额

from OrderMaster a,Customer b,OrderDetail c

where a.customerno=b.customerno and a.orderNo=c.orderNo and c.quantity>0

group by a.customerNo,b.customerName

实验结果:

(5)查询没有订购商品的客户编号和客户名称。

实验脚本:

select customerno 客户编号,customerName 客户名称

from Customer

where customerno not in(select customerno

from OrderMaster)

实验结果:

(6)使用子查询查找32M DRAM的销售情况,要求显示相应的销售员的姓名、性别,

销售日期、销售数量和金额,其中性别用“男”、“女”表示。

实验脚本:

select employeeName 姓名,orderdate 销售日期,quantity 销售金

额,(price*quantity)金额,

case a.sex

when'F'then'女'

when'M'then'男'

end as性别

from Employee a,OrderMaster b,OrderDetail c,Product d

where a.employeeNo=b.salerNo and b.orderNo=c.orderNo and

d.productNo=c.productNo

and productName='32M DRAM'

实验结果:

(7)查询OrderMaster表中订单金额最高的订单号及订单金额。

实验脚本:

select orderNo 订单号,orderSum 订单金额

from OrderMaster

where orderSum=(select max(orderSum)from OrderMaster) 实验结果

(8)在订单主表中查询订单金额大于“E2005002业务员在2008-1-9这天所接的任一张

订单的金额”的所有订单信息。

实验脚本:

select*

from OrderMaster

where orderSum>(select max(orderSum)

from ordermaster

where salerNo='E2005002'and orderDate='2008-1-9') 实验结果:

(9)查询单价高于400元的商品编号、商品名称、订货数量和订货单价。

实验脚本:

select a.productNo,productName,quantity,price

from OrderDetail a,Product b

where a.productNo=b.productNo and price>400

实验结果:

(10)分别使用左外连接、右外连接、完整外部连接查询单价高于400元的商品编号、商

品名称、订货数量和订货单价,并分析比较检索的结果。

左外连接:

实验脚本:

select a.productNo,productName,quantity,price

from OrderDetail as a left join Product as b

on(a.productNo=b.productNo and price>400)

相关文档
最新文档