数据库实验答案 下载本文

内容发布更新时间 : 2024/9/24 6:23:38星期一 下面是文章的全部内容请认真阅读。

select 型号 from PC电脑 where 速度= ( select MAX(速度) from PC电脑 where 内存= ( select MIN(内存) from PC电脑 ) ) and 内存 in ( select MIN(内存) from pc电脑 ) )

select 制造商

from 产品,PC电脑

where 产品.产品型号=PC电脑.型号 and PC电脑.速度= ( select MAX(速度) from PC电脑 where 内存<=all ( select 内存 from PC电脑 ) )

and 内存 in ( select min(内存) from pc电脑 )

create view vproduct(制造商,产品型号,产品类型,价钱,速度) as

select 制造商,产品型号,产品类型,价钱,速度 from 产品,PC电脑

where 产品.产品型号=PC电脑.型号 union

select 制造商,产品型号,产品类型,价钱,速度 from 产品,便携式电脑

精选文档

6

精选文档

where 产品.产品型号=便携式电脑.型号

1、找出销售 便携式电脑 但不销售 PC 的厂商。 select 制造商 from vproduct

where 产品类型 LIKE '便携式电脑' and 制造商 not in ( select 制造商 from 产品

where 产品类型 LIKE 'PC电脑' or 产品类型 LIKE '打印机' )

2、找出至少生产两种不同的计算机(PC或便携式电脑)且极其速度至少为133的厂商。 select distinct 制造商 from vproduct

where 速度>133 and 产品类型 LIKE 'PC电脑' or 产品类型 LIKE '便携式电脑' and 制造商 in

(select min(制造商) from vproduct group by 制造商

having COUNT(产品型号)>=2)

3、找出生产最高速度的计算机(PC电脑或便携式电脑)厂商。

select distinct 制造商 from vproduct

where 速度>133 and 产品类型 LIKE 'PC电脑' or 产品类型 LIKE '便携式电脑' and 制造商 in

(select min(制造商) from vproduct group by 制造商

having COUNT(产品型号)>=2) create view 最高速度1 as

select distinct 制造商 from 产品,PC电脑

where 产品.产品型号=PC电脑.型号 and 速度= ( select MAX(速度) from PC电脑 ) union

select distinct 制造商 from 产品,便携式电脑

where 产品.产品型号=便携式电脑.型号 and 速度= (

7

select MAX(速度) from 便携式电脑 )

4、找出至少生产三种不同速度 PC的厂商。 select distinct 制造商 from vproduct

where 产品类型 LIKE 'PC电脑' and 制造商 in (select min(制造商) from vproduct

group by 产品类型 having count(速度)>=3)

5.找出只卖三种不同型号的PC的厂商。 create view 三种 as

select 制造商 from 产品 A

where A.产品型号=any ( select 型号 from PC电脑 )

AND A.制造商 not in ( select B.制造商 from 产品 B where 产品类型='便携式电脑' or 产品类型='打印机' )

GROUP BY 制造商 having count(*)=3

create view vproduct3(制造商,产品型号,产品类型) as

select 制造商,产品型号,产品类型 from 产品

where 制造商 not in (select 制造商 from 产品

where 产品类型 LIKE '便携式电脑' or 产品类型 LIKE '打印机' )

select 制造商 from vproduct3 group by 制造商

having count(产品型号)>=2 select avg(速度) from PC电脑

精选文档

8

select avg(速度) from 便携式电脑 where 价钱>2500 select avg(价钱) from PC电脑 where 型号 in (select 产品型号 from 产品

where 制造商='A' )

实验六

1)找出PC的平均速度。 select AVG(速度) from vproduct3

where 产品类型='PC电脑'

2)找出价格超过2500美元的便携式电脑的平均速度。 select AVG(速度) from vproduct3

where 产品类型='便携式电脑' and 价钱>2500 3)找出厂商A生产PC的平均价格。 select AVG(价钱) from vproduct3

where 制造商='A' and 产品类型='PC电脑'

4)找出厂商D生产的PC和便携式电脑的平均价格。 select AVG(价钱) from vproduct3 where 制造商='D'

(5)找出各种不同速率的pc的平均价格 create view five as

select 价钱,速度 from PC电脑

select 速度,AVG(价钱) as 平均价钱 from five

group by 速度 直接查询

select 速度,AVG(价钱) from PC电脑 group by 速度

6)找出各厂商生产的便携式电脑的显示器平均尺寸。

create view vproduct4(制造商,产品型号,速度,价钱,屏幕大小) as

select 制造商,产品型号,速度,价钱,屏幕大小 from 产品,便携式电脑

精选文档

9

精选文档

where 产品.产品型号=便携式电脑.型号 select 制造商,AVG(屏幕大小) from vproduct4 group by 制造商

7)找出生产三种不同型号的PC的厂商。

create view vproduct5(制造商,产品型号,产品类型,价钱) as

select 制造商,产品型号,产品类型,价钱 from 产品,PC电脑

where 产品.产品型号=PC电脑.型号 select 制造商 from vproduct5 group by 制造商

having count(产品型号)=3

8)找出各厂商生产的PC的最高价格。 select 制造商,MAX(价钱) from vproduct5 group by 制造商

9)找出速度超过150MHz的各种速度的PC的平均价格。 select AVG(速度) from vproduct3

where 产品类型='PC电脑' and 速度>150

10)找出所有生产打印机的厂商生产PC的硬盘平均容量。 create view now as

select 制造商,产品型号 from 产品

where 制造商 in (select 制造商 from 产品

where 产品类型='打印机') and 产品类型='PC电脑' create view now1 as

select 制造商,产品型号,硬盘容量 from now,PC电脑

where now.产品型号=PC电脑.型号 select avg(硬盘容量)平均硬盘容量 from now1 实验七 1)

create procedure P1

@制造商 char(10),@产品型号 char(10),@产品类型 char(10),@速度 int,@内存 int,@硬盘容

10