![数据库实验答案_第1页](http://file3.renrendoc.com/fileroot_temp3/2022-4/27/5992a672-2015-4f85-b3da-68101a2b5b46/5992a672-2015-4f85-b3da-68101a2b5b461.gif)
![数据库实验答案_第2页](http://file3.renrendoc.com/fileroot_temp3/2022-4/27/5992a672-2015-4f85-b3da-68101a2b5b46/5992a672-2015-4f85-b3da-68101a2b5b462.gif)
![数据库实验答案_第3页](http://file3.renrendoc.com/fileroot_temp3/2022-4/27/5992a672-2015-4f85-b3da-68101a2b5b46/5992a672-2015-4f85-b3da-68101a2b5b463.gif)
![数据库实验答案_第4页](http://file3.renrendoc.com/fileroot_temp3/2022-4/27/5992a672-2015-4f85-b3da-68101a2b5b46/5992a672-2015-4f85-b3da-68101a2b5b464.gif)
![数据库实验答案_第5页](http://file3.renrendoc.com/fileroot_temp3/2022-4/27/5992a672-2015-4f85-b3da-68101a2b5b46/5992a672-2015-4f85-b3da-68101a2b5b465.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1)找出 MGM studios 的地址。select 地址 from 制片公司where 公司名称='MGM studios'2)找出 Sandra Bullock 的出生日期。select 生日from 电影明星where 姓名='Sandra Bullock'3)找出在2003年拍摄过电影的所有影星,或者拍摄过电影中含有"天空"的电影的所有明星。select 演员姓名from 演员参演电影where 拍摄年份=2003 or 电影名称 like'%天空%'4)找出净资产至少1000万美元的所有行政长官。select 姓名
2、from 制片人与行政总裁where 资产>=100000005)找出所有的男影星或者是住址中含有 Malibu 的影星。select 姓名from 电影明星where 地址 like 'Malibu' or 性别 like '男'1)电影"加勒比海盗4"中的男影星都有谁。select 姓名from 电影明星where 性别 ='男' and 姓名 in(select 演员姓名from 演员参演电影where 电影名称='加勒比海盗4')2)谁是米高梅制片公司的总裁。select 姓名from 制片人与行
3、政总裁where 身份证号 =(select 行政总裁from 制片公司where 公司名称 ='MGM studios')4)那些电影比乱世佳人更长。select 电影名称from 电影where 长度 >(select 长度from 电影where 电影名称 = '乱世佳人')5)那些行政长官比 Tom 更富有。select 姓名from 制片人与行政总裁where 资产>(select 资产from 制片人与行政总裁where 姓名='Tom')1、找出价格低于6000元的PC计算机型号、速度、以及硬盘容量。select 型号,
4、速度,硬盘容量from PC电脑where 价钱 < 60002、同上要求,另外将 "速度" 改名为 "兆赫",将 "硬盘" 改名为 "G字节"。select 型号,速度 兆赫,硬盘容量 G字节from PC电脑where 价钱 < 60003、找出打印机的制造商。select 制造商from 产品where 产品类型 = '打印机'4、找出价格高于2000元的"便携式电脑"的型号、内存容量及屏幕大小。select 型号,内存,屏幕大小from 便携式电脑where
5、价钱 > 60005、从"打印机"关系中找出所有彩色打印机的元组。select *from 打印机where 是否彩色 = '是'6、找出具有300GB以上的硬盘容量而价格低于2000元的所有个人计算机的型号、速度及硬盘。select 型号,速度,硬盘容量from PC电脑where 硬盘容量>300 and 价钱 <60001、找出配置了容量至少为300GB硬盘的便携式电脑的制造商及其速度。select 制造商,速度from 产品,便携式电脑where 产品型号=便携式电脑.型号 and 硬盘>3002、找出由生产厂商"苹
6、果"生产的所有产品的型号和价格。select 型号,价钱from PC电脑where 型号 in(select 产品型号from 产品where 制造商='苹果')unionselect 型号,价钱from 便携式电脑where 型号 in(select 产品型号from 产品where 制造商='苹果')unionselect 型号,价钱from 打印机where 型号 in(select 产品型号from 产品where 制造商='苹果')3、找出所有出售"便携式电脑"(而不出售PC)的生产厂商。select 制
7、造商from 产品where 产品类型 LIKE '便携式电脑' and 制造商 not in(select 制造商from 产品where 产品类型 LIKE 'PC电脑' or 产品类型 LIKE '打印机')4、找出在两种或两种以上PC上出现的硬盘容量。select 硬盘容量from PC电脑group by 硬盘容量having count(*)>=25、找出拥有相同速度和内存的PC的成对的型号。select distinct Q.型号,P.型号from PC电脑 Q, PC电脑 Pwhere Q.速度=P.速度 and Q.内存=
8、P.内存 and Q.型号<P.型号1、找出速度至少为1500MHz的"PC电脑"制造商。("=any"和"in")select distinct 制造商from 产品where 产品类型='PC电脑' and 产品型号 in(select 型号from PC电脑where 速度>=1500)2、找出价格最高的打印机。(注意 ">all" 和 ">any" 的区别) (">=all"和"=max()")sele
9、ct 型号from 打印机where 价钱 >=all(select 价钱from 打印机)3、找出速度低于任何PC的便携式电脑。(注意"<all"和"<any"的区别)select 型号from 便携式电脑where 速度 < all(select 速度from PC电脑)4、找出具有最高价格的机器(PC,便携式电脑或打印机)的型号。select 型号from PC电脑where 价钱=(select MAX(价钱)from PC电脑)unionselect 型号from 便携式电脑where 价钱=(select MAX(价钱
10、)from 便携式电脑)unionselect 型号from 打印机where 价钱=(select MAX(价钱)from 打印机)5、找出具有最低价格的彩色"打印机"的制造商。("=any和in" "<=all和MIN()")select 制造商from 产品where 产品型号 =any(select 型号from 打印机where 价钱<=all(select 价钱from 打印机where 是否彩色 ='是')6、找出在具有最小内存容量的所有 PC 中,具有最快处理器的 PC 制造商。select
11、 制造商from 产品where 产品型号 =any(select 型号from PC电脑where 速度 =(select MAX(速度) from PC电脑where 内存<=all(select 内存from PC电脑)and 内存 in(select min(内存)from pc电脑)select 制造商from 产品where 产品型号 in(select 型号from PC电脑where 速度=(select MAX(速度)from PC电脑where 内存=(select MIN(内存)from PC电脑)and 内存 in(select MIN(内存)from pc电脑)
12、select 制造商from 产品,PC电脑where 产品.产品型号=PC电脑.型号 andPC电脑.速度=(select MAX(速度)from PC电脑where 内存<=all(select 内存from PC电脑)and 内存 in(select min(内存)from pc电脑)create view vproduct(制造商,产品型号,产品类型,价钱,速度)asselect 制造商,产品型号,产品类型,价钱,速度from 产品,PC电脑where 产品.产品型号=PC电脑.型号unionselect 制造商,产品型号,产品类型,价钱,速度from 产品,便携式电脑where
13、 产品.产品型号=便携式电脑.型号1、找出销售 便携式电脑 但不销售 PC 的厂商。select 制造商from vproductwhere 产品类型 LIKE '便携式电脑' and 制造商 not in( select 制造商 from 产品 where 产品类型 LIKE 'PC电脑' or 产品类型 LIKE '打印机')2、找出至少生产两种不同的计算机(PC或便携式电脑)且极其速度至少为133的厂商。select distinct 制造商from vproductwhere 速度>133 and 产品类型 LIKE 'PC
14、电脑' or 产品类型 LIKE '便携式电脑' and 制造商 in(select min(制造商)from vproductgroup by 制造商having COUNT(产品型号)>=2)3、找出生产最高速度的计算机(PC电脑或便携式电脑)厂商。select distinct 制造商from vproductwhere 速度>133 and 产品类型 LIKE 'PC电脑' or 产品类型 LIKE '便携式电脑' and 制造商 in(select min(制造商)from vproductgroup by 制造商h
15、aving COUNT(产品型号)>=2)create view 最高速度1asselect distinct 制造商from 产品,PC电脑where 产品.产品型号=PC电脑.型号and 速度=(select MAX(速度)from PC电脑)unionselect distinct 制造商from 产品,便携式电脑where 产品.产品型号=便携式电脑.型号and 速度=(select MAX(速度)from 便携式电脑 )4、找出至少生产三种不同速度 PC的厂商。select distinct 制造商from vproductwhere 产品类型 LIKE 'PC电脑
16、39; and 制造商 in (select min(制造商) from vproduct group by 产品类型 having count(速度)>=3)5.找出只卖三种不同型号的PC的厂商。create view 三种asselect 制造商from 产品 A where A.产品型号=any(select 型号from PC电脑 )AND A.制造商 not in (select B.制造商from 产品 Bwhere 产品类型='便携式电脑' or 产品类型='打印机' )GROUP BY 制造商having count(*)=3create
17、view vproduct3(制造商,产品型号,产品类型)asselect 制造商,产品型号,产品类型from 产品where 制造商 not in(select 制造商 from 产品 where 产品类型 LIKE '便携式电脑' or 产品类型 LIKE '打印机')select 制造商from vproduct3group by 制造商having count(产品型号)>=2select avg(速度)from PC电脑select avg(速度)from 便携式电脑where 价钱>2500select avg(价钱)from PC电脑w
18、here 型号 in(select 产品型号from 产品 where 制造商='A')实验六1)找出PC的平均速度。select AVG(速度)from vproduct3 where 产品类型='PC电脑'2)找出价格超过2500美元的便携式电脑的平均速度。select AVG(速度)from vproduct3where 产品类型='便携式电脑' and 价钱>25003)找出厂商A生产PC的平均价格。select AVG(价钱)from vproduct3where 制造商='A' and 产品类型='PC电
19、脑'4)找出厂商D生产的PC和便携式电脑的平均价格。select AVG(价钱)from vproduct3where 制造商='D'(5)找出各种不同速率的pc的平均价格create view fiveasselect 价钱,速度from PC电脑select 速度,AVG(价钱) as 平均价钱from fivegroup by 速度直接查询select 速度,AVG(价钱)from PC电脑group by 速度6)找出各厂商生产的便携式电脑的显示器平均尺寸。create view vproduct4(制造商,产品型号,速度,价钱,屏幕大小)asselect 制造
20、商,产品型号,速度,价钱,屏幕大小from 产品,便携式电脑where 产品.产品型号=便携式电脑.型号select 制造商,AVG(屏幕大小)from vproduct4group by 制造商7)找出生产三种不同型号的PC的厂商。create view vproduct5(制造商,产品型号,产品类型,价钱)asselect 制造商,产品型号,产品类型,价钱from 产品,PC电脑 where 产品.产品型号=PC电脑.型号select 制造商from vproduct5group by 制造商having count(产品型号)=38)找出各厂商生产的PC的最高价格。select 制造商,
21、MAX(价钱)from vproduct5group by 制造商9)找出速度超过150MHz的各种速度的PC的平均价格。select AVG(速度)from vproduct3where 产品类型='PC电脑' and 速度>15010)找出所有生产打印机的厂商生产PC的硬盘平均容量。create view nowasselect 制造商,产品型号from 产品where 制造商 in(select 制造商 from 产品where 产品类型='打印机')and 产品类型='PC电脑'create view now1asselect 制造
22、商,产品型号,硬盘容量from now,PC电脑where now.产品型号=PC电脑.型号select avg(硬盘容量)平均硬盘容量from now1实验七1)create procedure P1制造商 char(10),产品型号 char(10),产品类型 char(10),速度 int,内存 int,硬盘容量 int,价钱 money asbegin transactiondeclare error1 intinsert into 产品 values(制造商,产品型号,产品类型)set error1=error1+errorinsert into PC电脑 values(产品型号,速
23、度,内存,硬盘容量,价钱)set error1=error1+errorif(error1<>0) beginprint '插入失败,回滚事物'rollback transactionendelsebeginprint '成插入成功,提交事物'commit transactionendexec P1 制造商='C',产品型号='11100',产品类型='PC电脑',速度=240,内存=32,硬盘容量='2.5',价钱=24992)create procedure P2 as begin
24、transactiondeclare Error2 intinsert into 产品(制造商,产品型号,产品类型)select 制造商,产品型号+'1100','便携式电脑'from 产品where 产品.产品类型='PC电脑'set Error2=Error2+errorinsert into 便携式电脑(型号,速度,内存,硬盘,屏幕大小,价钱)select 型号+'1100',速度,内存,硬盘容量,11,价钱+500from PC电脑set Error2=Error2+errorif(Error2<>0)begi
25、nprint'插入失败,回滚事物'rollback transactionendelsebeginprint'插入成功,提交事物'commit transactionend3)create trigger P3on PC电脑for deleteasdelete from 产品where 产品型号 in (select 型号 from deleted)delete from PC电脑where 硬盘容量<50create trigger P4on 产品for updateasdeclare 型号1 char(10)declare 制造商 char(10)se
26、lect 型号1=产品型号 from insertedselect 制造商=制造商from inserted bwhere b.产品型号=型号1if 制造商 is nullbegin print '错误!'rollback transactionendupdate 产品set 制造商='A'where 制造商='B'(4)厂商A收购了B,将所有由B制造的产品改为A制造declare MyCursor cursorDYNAMICfor select 制造商,产品型号,产品类型from 产品where 制造商 = 'B'for upd
27、ateopen MyCursorfetch next from MyCursorupdate 产品set 制造商 = 'A'where current of MyCursorwhile(FETCH_STATUS =0)beginfetch next from MyCursorupdate 产品set 制造商 = 'A'where current of MyCursorENDdeallocate MyCursorcreate database Moviescreate table 电影明星( 姓名 varchar(20) not null primary key,
28、 地址 varchar(50), 性别 char(2)check(性别='男' or 性别='女'), 生日 datetime);create table 制作人与行政总裁( 姓名 varchar(20), 地址 varchar(50), 身份证号 char(18) not null primary key, 资产 int);create table 制片公司( 公司名称 varchar(50) not null primary key, 地址 varchar(50), 行政总裁 char(18)not null references 制作人与行政总裁(身份证号),);create table 电影( 电影名称 varchar(50) n
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年人社部的劳动合同(三篇)
- 2025年九年级英语下册教学工作总结范例(二篇)
- 2025年中外来料加工、来件装配合同样本(2篇)
- 2025年代理权转让的合同(2篇)
- 2025年企业产品购销合同参考模板(三篇)
- 2025年九年级英语培优辅差总结样本(二篇)
- 人工智能居间服务合同范本
- 亲子餐厅装修施工合同样本
- 植生混凝土技术施工方案
- 木材加工居间合作协议
- 端午做香囊课件
- 外观判定标准
- 江西上饶市2025届数学高二上期末检测试题含解析
- 脑卒中后吞咽障碍患者进食护理团体标准
- 墨香里的年味儿(2023年辽宁沈阳中考语文试卷记叙文阅读题及答案)
- 2024-2030年市政工程行业发展分析及投资战略研究报告
- 济宁医学院成人高等教育期末考试《无机化学》复习题
- 工行人工智能风控
- 新概念英语第二册考评试卷含答案(第73-80课)
- 中医腕踝针技术
- 2023风电机组预应力混凝土塔筒与基础结构设计标准
评论
0/150
提交评论