1、数据库实验答案1)找出 MGM studios 的地址。select 地址 from 制片公司where 公司名称=MGM studios2)找出 Sandra Bullock 的出生日期。select 生日from 电影明星where 姓名=Sandra Bullock3)找出在2003年拍摄过电影的所有影星,或者拍摄过电影中含有天空的电影的所有明星。select 演员姓名from 演员参演电影where 拍摄年份=2003 or 电影名称 like%天空%4)找出净资产至少1000万美元的所有行政长官。select 姓名from 制片人与行政总裁where 资产=100000005)找出所
2、有的男影星或者是住址中含有 Malibu 的影星。select 姓名from 电影明星where 地址 like Malibu or 性别 like 男1)电影加勒比海盗4中的男影星都有谁。select 姓名from 电影明星where 性别 =男 and 姓名 in( select 演员姓名 from 演员参演电影 where 电影名称=加勒比海盗4)2)谁是米高梅制片公司的总裁。select 姓名from 制片人与行政总裁where 身份证号 =( select 行政总裁 from 制片公司 where 公司名称 =MGM studios)4)那些电影比乱世佳人更长。select 电影名称
3、from 电影where 长度 ( select 长度 from 电影 where 电影名称 = 乱世佳人)5)那些行政长官比 Tom 更富有。select 姓名from 制片人与行政总裁where 资产( select 资产 from 制片人与行政总裁 where 姓名=Tom)1、找出价格低于6000元的PC计算机型号、速度、以及硬盘容量。select 型号,速度,硬盘容量from PC电脑where 价钱 60002、同上要求,另外将 速度 改名为 兆赫,将 硬盘 改名为 G字节。select 型号,速度 兆赫,硬盘容量 G字节from PC电脑where 价钱 60005、从打印机关系
4、中找出所有彩色打印机的元组。select *from 打印机where 是否彩色 = 是6、找出具有300GB以上的硬盘容量而价格低于2000元的所有个人计算机的型号、速度及硬盘。select 型号,速度,硬盘容量from PC电脑where 硬盘容量300 and 价钱 3002、找出由生产厂商苹果生产的所有产品的型号和价格。select 型号,价钱from PC电脑where 型号 in( select 产品型号 from 产品 where 制造商=苹果)unionselect 型号,价钱from 便携式电脑where 型号 in( select 产品型号 from 产品 where 制造
5、商=苹果)unionselect 型号,价钱from 打印机where 型号 in( select 产品型号 from 产品 where 制造商=苹果)3、找出所有出售便携式电脑(而不出售PC)的生产厂商。select 制造商from 产品where 产品类型 LIKE 便携式电脑 and 制造商 not in( select 制造商 from 产品 where 产品类型 LIKE PC电脑 or 产品类型 LIKE 打印机)4、找出在两种或两种以上PC上出现的硬盘容量。select 硬盘容量from PC电脑group by 硬盘容量having count(*)=25、找出拥有相同速度和内
6、存的PC的成对的型号。select distinct Q.型号,P.型号from PC电脑 Q, PC电脑 Pwhere Q.速度=P.速度 and Q.内存=P.内存 and Q.型号=1500)2、找出价格最高的打印机。(注意 all 和 any 的区别) (=all和=max()select 型号from 打印机where 价钱 =all( select 价钱 from 打印机)3、找出速度低于任何PC的便携式电脑。(注意all和any的区别)select 型号from 便携式电脑where 速度 all( select 速度 from PC电脑)4、找出具有最高价格的机器(PC,便携式
7、电脑或打印机)的型号。select 型号from PC电脑where 价钱=( select MAX(价钱) from PC电脑)unionselect 型号from 便携式电脑where 价钱=( select MAX(价钱) from 便携式电脑)unionselect 型号from 打印机where 价钱=( select MAX(价钱) from 打印机)5、找出具有最低价格的彩色打印机的制造商。(=any和in =all和MIN()select 制造商from 产品where 产品型号 =any( select 型号 from 打印机 where 价钱=all ( select 价钱
8、 from 打印机 where 是否彩色 =是 )6、找出在具有最小内存容量的所有 PC 中,具有最快处理器的 PC 制造商。select 制造商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 速度= ( sele
9、ct MAX(速度) from PC电脑 where 内存= ( select MIN(内存) from PC电脑 ) ) and 内存 in ( select MIN(内存) from pc电脑 )select 制造商from 产品,PC电脑where 产品.产品型号=PC电脑.型号 andPC电脑.速度=( select MAX(速度) from PC电脑 where 内存133 and 产品类型 LIKE PC电脑 or 产品类型 LIKE 便携式电脑 and 制造商 in(select min(制造商)from vproductgroup by 制造商having COUNT(产品型号
10、)=2)3、找出生产最高速度的计算机(PC电脑或便携式电脑)厂商。select distinct 制造商from vproductwhere 速度133 and 产品类型 LIKE PC电脑 or 产品类型 LIKE 便携式电脑 and 制造商 in(select min(制造商)from vproductgroup by 制造商having COUNT(产品型号)=2)create view 最高速度1asselect distinct 制造商from 产品,PC电脑where 产品.产品型号=PC电脑.型号and 速度=( select MAX(速度) from PC电脑)unionsel
11、ect distinct 制造商from 产品,便携式电脑where 产品.产品型号=便携式电脑.型号and 速度=( select MAX(速度) from 便携式电脑 )4、找出至少生产三种不同速度 PC的厂商。select distinct 制造商from vproductwhere 产品类型 LIKE PC电脑 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 产品 B where 产品类型=
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1