SQL语句---关系代数

1、第一大题

编程要求

本关使用的关系说明:

product(maker,model,type)
maker:表示生产厂商
model:生产的产品型号
type:产品类型,有pc laptop printer三种

pc(model,speed,ram,hd,price)
表示型号,速度,内存大小,硬盘大小,价格

laptop(model,speed,ram,hd,screen,price)
表示型号,速度,内存大小,硬盘大小,屏幕大小和价格

printer(model,color,type,price)
表示的含义是
model:打印机型号;
color:是否彩色, T 彩色,F 黑白
type:类型,ink-jet 表示喷墨, laser 表示激光;
price:单价

  • 补全右侧代码片段中 第1题 下 Begin-End 区间的代码,查询生产pc也生产laptop的厂商。
  • 补全右侧代码片段中 第2题 下 Begin-End 区间的代码,查询生产型号为2001的厂商信息及该型号所属产品的种类。
  • 补全右侧代码片段中 第3题 下 Begin-End 区间的代码,查询厂商A 生产的PC中price大于900的产品型号。
  • 补全右侧代码片段中 第4题 下 Begin-End 区间的代码,查询生产ink-jet的打印机的厂商及价格。
  • 补全右侧代码片段中 第5题 下 Begin-End 区间的代码,查询厂商B生产的所有产品的型号和价格。
USE test_wyy_db_guet
GO
SET NOCOUNT ON
-- ********** Begin ********** --
-- ********** 此处写第一题的SQL语句 ********** --
select maker from product where type='pc'
intersect
select maker from product where type='laptop'
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第二题的SQL语句 ********** --
select maker,type from product where model='2001'
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第三题的SQL语句 ********** --
select pc.model 
from product,pc 
where product.model=pc.model and maker='A' and price>900
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第四题的SQL语句 ********** --
select maker,price
from product,printer
where printer.model=product.model and printer.type='ink-jet'
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第五题的SQL语句 ********** --
select product.model,price
from product,pc
where product.model=pc.model
and maker='B'
union
select product.model,price
from product,laptop
where product.model=laptop.model
and maker='B'
union
select product.model,price
from product,printer
where product.model=printer.model
and maker='B'
-- ********** End ********** --
GO

2、第二大题

编程要求

  • 补全右侧代码片段中 第1题 下 Begin-End 区间的代码,分类统计厂商(maker)A生产的各种产品的数量。(提示:用分组操作符)
  • 补全右侧代码片段中 第2题 下 Begin-End 区间的代码,查询所有彩色激光打印机的生产商及型号。
  • 补全右侧代码片段中 第3题 下 Begin-End 区间的代码, 找出生产产品型号最多的厂商。
  • 补全右侧代码片段中 第4题 下 Begin-End 区间的代码,查询出哪个生产厂商的笔记本电脑的硬盘容量至少100G。
  • 补全右侧代码片段中 第5题 下 Begin-End 区间的代码,找出那些既出售笔记本电脑又出售PC的厂商。
USE test_wyy_db_guet
GO
SET NOCOUNT ON
-- ********** Begin ********** --
-- ********** 此处写第一题的SQL语句 ********** --
select type,count(*)
from product
where maker='A'
group by type
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第二题的SQL语句 ********** --
select maker,model
from product
where model in (select model from printer where color='T' and type='laser')
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第三题的SQL语句 ********** --
select top 1 maker
from product
group by maker
order by count(model) desc
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第四题的SQL语句 ********** --
select distinct maker
from product,laptop
where product.model=laptop.model and hd>=100
except
select distinct maker
from product,laptop
where product.model=laptop.model and hd<100
-- ********** End ********** --

GO
-- ********** Begin ********** --
-- ********** 此处写第五题的SQL语句 ********** --
select maker
from product
where type='pc'
intersect
select maker
from product
where type='laptop'
-- ********** End ********** --
GO

3、第三大题

编程要求

  • 补全右侧代码片段中 第1题 下 Begin-End 区间的代码,查询具有同样处理速度和同样内存大小的PC对(显示满足条件的pc对的型号,同样的pc对只出现1次,如001 与 002 符合条件, 则仅出现001 002,不出现002 001)。
  • 补全右侧代码片段中 第2题 下 Begin-End 区间的代码,查询至少生产三种不同处理速度电脑(含pc和laptop)的厂商。
  • 补全右侧代码片段中 第3题 下 Begin-End 区间的代码,统计出pc,laptop,printer三种产品的不同型号数量,并按数量从大到小排序。
  • 补全右侧代码片段中 第4题 下 Begin-End 区间的代码,有客户有1500元钱,买laptop或pc,要求硬盘容量不小于80,请给出可能的产品型号,生产厂商。
  • 补全右侧代码片段中 第5题 下 Begin-End 区间的代码,找出至少生产5种不同型号产品的厂商。
USE test_wyy_db_guet
GO
SET NOCOUNT ON 
-- ********** Begin ********** --
-- ********** 此处写第一题的SQL语句 ********** --
select pc1.model,pc2.model
from pc pc1,pc pc2
where pc1.speed=pc2.speed
and pc1.ram=pc2.ram
and pc1.model<pc2.model
-- ********** End ********** --
GO 
-- ********** Begin ********** --
-- ********** 此处写第二题的SQL语句 ********** --
select maker
from product,(select model,speed from pc union select model,speed from laptop)pclap
where product.model=pclap.model
group by maker
having count(distinct speed)>=3
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第三题的SQL语句 ********** --
select type,count(*) as c
from product
group by type
order by c desc
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第四题的SQL语句 ********** --
select maker,model
from product
where model in
(select model from laptop where hd>=80 and price<=1500 
union select model from pc where hd>=80 and price<=1500)
order by model
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第五题的SQL语句 ********** --
select maker
from product
group by maker
having count(maker)>=5
-- ********** End ********** --
GO

4、第四大题

编程要求

  • 补全右侧代码片段中 第1题 下 Begin-End 区间的代码,完成功能使得:厂商A的产品升级,所有pc速度提高100,硬盘容量增加50,价格上调300。
  • 补全右侧代码片段中 第2题 下 Begin-End 区间的代码,完成功能:厂商E新增一种pc产品,型号1090,速度200,内存128,硬盘160,价格800。
  • 补全右侧代码片段中 第3题 下 Begin-End 区间的代码,完成功能:厂商C生产的laptop,型号2013停产,需要从相关关系种去除。
  • 补全右侧代码片段中 第4题 下 Begin-End 区间的代码,完成功能:厂商A生产的产品1001型号变更为1091,其余信息不变。
  • 补全右侧代码片段中 第5题 下 Begin-End 区间的代码,厂商H破产,所有其生产的产品需移除。
USE test_wyy_db_guet
GO
SET NOCOUNT ON 
-- ********** Begin ********** --
-- ********** 此处写第一题的SQL语句 ********** --
update pc
set speed+=100,hd+=50,price+=300
where model in (select model from product where maker='A') 
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第二题的SQL语句 ********** --
insert into product
values('E','1090','pc')
insert into pc
values('1090',200,128,160,800)
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第三题的SQL语句 ********** --
delete from laptop
where model='2013'
delete from product
where model='2013' and maker='C'
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第四题的SQL语句 ********** --
update product
set model='1091'
where model='1001'
update pc
set model='1091'
where model='1001'
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第五题的SQL语句 ********** --
delete from pc where model in (select model from product where maker='H')
delete from laptop where model in (select model from product where maker='H')
delete from printer where model in (select model from product where maker='H')
delete from product where  model='3006'
delete from product where  model='3007' 
-- ********** End ********** --
GO
-- **********下面的语句请勿删除 ********** --
select * from pc
select * from laptop
select * from printer
select * from product
GO
  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值