SQL 习题2
时间:2021-07-01 10:21:17
帮助过:9人阅读
Xk
go
--拓展小练习:查询课程信息,报名人数占限选人数之比。要求查询结果按报名人数降序排序,(且只显示结果的前10行)
select top 10 percent *,
‘报名人数占限选人数之比‘=WillNum
/LimitNum
from Course
order by WillNum
desc
go
--13、查询课程表的教师名,课程号,课程名,要求查询结果按教师名降序排列,教师名相同时,按课程号升序排列。
select Teacher,CouNo,CouName
from Course
order by Teacher
desc, CouNo
go
--14、在课程表中查询周二开设的选修课,要求按上课时间排序查询结果
select * from Course
where SchoolTime
like ‘周二%‘ order by SchoolTime
go
--拓展小练习:查询非周二开设的选修课
select * from Course
where SchoolTime
like ‘周[^二]%‘ order by SchoolTime
go
select * from Course
where SchoolTime
not like ‘周二%‘ order by SchoolTime
go
--15、查询选课表中随机数无值得数据行(使用is null)
select * from StuCou
where RandomNum
=‘‘
go
--16、统计Course表中提供了多少门选修课
select COUNT(
*)
as ‘提供多少门选修课‘ from Course
go
--17、查询课程表中能提供选修课程的总人数。
select SUM(LimitNum)
as ‘能提供课程的总人数‘ from Course
go
--18、查看课程表中最少报名人数、最多报名人数和平均报名人数
select MIN(WillNum)
as ‘最少报名人数‘,
MAX(WillNum)
as ‘最多报名人数‘,
CONVERT(
DECIMAL(
5,
2),
AVG(WillNum))
as ‘平均报名人数‘ from Course
go
--19、按课程类别分组统计各类课程的门数
select Kind
as ‘课程类别‘,
COUNT(kind)
as ‘各类课程的门数‘ from Course
group by Kind
go
--20、按课程类别分组统计各类课程的门数,并给出课程的总门数。
select Kind
as ‘课程类别‘,
COUNT(kind)
as ‘各类课程的门数‘ from Course
group by Kind
with CUBE
go
--21、查看报名人数大于15的各类课程的最少报名人数和最多报名人数
select Kind
as ‘课程类别‘,
MIN(WillNum)
as ‘最少报名人数‘,
MAX(WillNum)
as ‘最多报名人数‘ from Course
where WillNum
>15 group by Kind
go
--22、查看报名人数大于15并且每组平均报名人数大于30的课程类别和各组的平均报名人数
select ‘课程类别‘=Kind,
‘平均报名人数‘=AVG(WillNum)
from Course
where WillNum
>15
group by Kind
having AVG(WillNum)
>30
go
SQL 习题2
标签:课程 mit 练习 not class ima 使用 name 随机数