资源描述
GDOU-B-11-112
广东海洋大学学生实验报告书
实验名称
实验四:使用子查询
课程名称
数据库原理与设计
成绩
学院(系)
软件学院
专业
计算机软件工程
班级
学生姓名
学号
实验地点
实验日期
实验目的:
1. 掌握带谓词IN的子查询;
2. 掌握带存在量词的子查询;
3. 掌握使用比较运算符的子查询;
4. 掌握使用限量谓词的子查询;
5. 综合运用所学知识实现查询;
6. 掌握SELECT INTO语句和UNION语句
实验内容
完成在在Recruitment,GlobalToyz和Student数据库基础上的查询,按要求完成给出的下列题目,要求写出相应数据库的查询语句(SELECT)。
1. 将售价大于9元的玩具信息拷贝到一张局部临时表中,该表仅在一次会话中存在。
2. 查询截止日期(dExpiryDate)在2001年5月的订购者(Shopper)的姓名和所在城市。
3. 根据玩具品牌统计每种品牌的平均价格,输出其中平均价格最高的品牌ID以及平均价格。
4. 检索每一类(类别用cCategoryId表示)玩具里价格最高的玩具的名称。
5. 检索价格最高的玩具的品牌(品牌为Brand)名称。
6. 要求必须用带EXISTS量词的嵌套查询实现,检索和‘David Cooper’住在同一个州的订购者(Shopper)的姓和名。
7. 检索‘California’州的订购者(Shopper)和接收人(Recipient)的姓名以及住址。
8. 检索订购者的人数,他们和‘Lisa Lee’使用同一种类型的信用卡。
9. 检索订购了玩具品牌为‘Largo’的订购者的姓和名。(多层嵌套查询实现)
10. 检索价格不低于所有品牌ID为‘005’的玩具的名称。
指导教师
日期
注:请用A4纸书写,不够另附纸。 第 页,共 页
1. select * into #temptoys from toys where mToyRate>9
2. select vFirstname,vLastname,cCity from Shopper where datepart(yy,dExpiryDate)=2001 and datepart(mm,dExpirydate)=5
3. select cBrandId,Avg(mToyrate) from Toys Group by cBrandId having avg(mToyrate)>= all(select avg(mToyrate) from toys group by cBrandId)
4. select vToyname from Toys a where mToyrate=(select max(mToyrate) from Toys b where b.cCategoryId=a.cCategoryId)
5. select cBrandName from ToyBrand where cBrandId in(select cBrandId from Toys where mToyrate=(select max(mToyrate) from toys))
6. select vFirstname,vLastname from Shopper a where exists(select * from Shopper b where vFirstname=’David’ and vLastname=’Cooper’ and b.cState=a.cState)
7. select vFirstname,vLastname,vAddress from Shopper where cState=’California’union select vFirstname,vLastname,vAddress from Recipient where cState=’California’
8. select count(*) from shopper where vCreditCardType in(select vCreditCardType from Shopper where vFirstname=’Lisa’ and vLastname=’Lee’
9. select vFirstname,vLastname from Shopper where cShopperId in(select cShopperId from orders where cOrderNo in(select cOrderNo from Orderdetail where cToyId in (select cToyId from toys where cBrandId in(select cBrandid from toybrand where cBrandName=’Largo’))))
10. select vToyname from toys where mToyrate>=some(select mToyrate from Toys where cBrandid=’005’)
展开阅读全文