1.查看课程表中系部编号为01的课程信息,同时显示该系部的平均报名人数
SELECT *
FROM Course
WHERE DepartNo='01'
Compute AVG(WillNum)
2.按系部分组显示课程信息,并显示各系部的平均报名人数
SELECT *
FROM Course
ORDER BY DepartNo
Compute AVG(WillNum) BY DepartNo
3.查询报名人数大于平均报名人数的课程信息
SELECT*
FROM Course
WHERE WillNum>(SELECT AVG(WillNum)FROM Course)
4.查询学生选课表中报名状态为“报名”的课程名称
SELECT DISTINCT CouName
FROM Course,StuCou
WHERE StuCou.CouNo=Course.CouNo AND State='报名'
5.查询已经报名选修课的学生信息,要求显示学号和姓名
select Student.StuNo,StuName
From Student
where exists(select StuNo
From StuCou
where StuNo=Student.StuNo)
6.查询课程表的所有信息,要求查询结果按照报名人数排序,并且返回每一行的序号、有间断的每一行的序号、没有间断的每一行的序号。比较运行结果
SELECT ROW_NUMBER()OVER(ORDER BY WillNum) AS 'Row Number',*
FROM Course
SELECT RANK()OVER(ORDER BY WillNum) AS 'RANK',*
FROM Course
SELECT DENSE_RANK()OVER(ORDER BY WillNum) AS 'DENSE_RANK',*
FROM Course
暮色醉
发布了1 篇原创文章 · 获赞 0 · 访问量 26
私信
关注