1、数据统计(初级)
编程要求
-
补全右侧代码片段中 第一题 下 Begin-End 区间的代码,统计 course表中学分数(credit)大于2的课程门数;
-
补全右侧代码片段中 第二题 下 Begin-End 区间的代码,统计所有专业必修课(BT开头的课程代码)的学分总数。
-
补全右侧代码片段中 第三题 下 Begin-End 区间的代码,按课程类别统计每个类别课程的门数,如课程代码BT001,BT002都是专业必修课。
本题使用的关系如下:
course(cno,cname,credit)
对应课程代码,课程名称,学分,其中课程代码前2位代表不同类型的课程,如BT 代表 专业必修课,XZ 代表专业限选课。
USE test_wyy_db_guet
GO
SET NOCOUNT ON
-- ********** Begin ********** --
-- ********** 此处写第一题的SQL语句 ********** --
select count(cno)
from course
where credit>2
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第二题的SQL语句 ********** --
select sum(credit)
from course
where cno like 'BT%'
-- ********** End ********** --
GO
-- ********** Begin ********** --
-- ********** 此处写第三题的SQL语句 ********** --
select substring(cno,1,2),count(cno)
from course
group by substring(cno,1,2)
-- ********** End ********** --
GO
2、数据统计初级应用
编程要求
使用的关系为printer(model,color,type,price)
表示的含义是
model:打印机型号;
color:是否彩色, T 彩色,F 黑白
type:类型,ink-jet 表示喷墨, laser 表示激光;
price:单价
- 补全右侧代码片段中 第一题 下 Begin-End 区间的代码,统计激光彩色打印机有多少种型号;
- 补全右侧代码片段中 第二题 下 Begin-End 区间的代码,找出最便宜的喷墨打印机价格。
- 补全右侧代码片段中 第三题 下 Begin-End 区间的代码,找出最贵的激光打印机型号和价格。
USE test_wyy_db_guet
Go
SET NOCOUNT ON
-- ********** Begin ********** --
---------- 第一题----------
select count(distinct type) from printer
-- ********** End ********** --
GO
-- ********** Begin ********** --
---------- 第二题----------
select min(price) from printer where type = 'ink-jet'
-- ********** End ********** --
GO
-- ********** Begin ********** --
---------- 第三题----------
select model,price from printer
where price =
(select max(price) from printer where type = 'laser')
-- ********** End ********** --
GO
3、数据统计综合应用
编程要求
product(maker,model,type)
maker:表示生产厂商
model:生产的产品型号
type:产品类型,有pc laptop两种
pc(model,speed,ram,hd,price)
表示型号,速度,内存大小,硬盘大小,价格
laptop(model,speed,ram,hd,screen,price)
表示型号,速度,内存大小,硬盘大小,屏幕大小和价格
了解视图的详细信息可参考下面的创建视图语句:
create view V_test as
select product.maker,product.model,product.type,pc.price,pc.hd,pc.speed
from product join pc on product.model=pc.model
union
select product.maker,product.model,product.type,laptop.price,laptop.hd,laptop.speed
from product join laptop on product.model=laptop.model
-
补全右侧代码片段中 第1题 下 Begin-End 区间的代码,查询在一种或两种电脑(含PC和laptop)中出现过的硬盘的容量。
-
补全右侧代码片段中 第2题 下 Begin-End 区间的代码,统计各生产厂商生产的电脑(不区分pc和laptop)的平均处理速度的最大值。
-
补全右侧代码片段中 第3题 下 Begin-End 区间的代码,统计出各厂商生产价格高于1000的产品数量,不用区分是pc还是laptop
-
补全右侧代码片段中 第4题 下 Begin-End 区间的代码,分别统计各厂商生产的pc,laptop的平均价格。
USE test_wyy_db_guet
Go
SET NOCOUNT ON
---------- 第1题 ----------
-- ********** Begin ********** --
select hd from v_test
group by hd
having count(model)<3
-- ********** End ********** --
GO
---------- 第2题 ----------
-- ********** Begin ********** --
select max(AVGSPD)
from (select avg(speed) as AVGSPD from V_test group by maker)
as AVGTable
-- ********** End ********** --
GO
---------- 第3题 ----------
-- ********** Begin ********** --
select maker, count(*)
from v_test
where price > 1000
group by maker
-- ********** End ********** --
GO
---------- 第4题 ----------
-- ********** Begin ********** --
select maker,type, avg(price)
from V_test
group by maker,type
-- ********** End ********** --
GO