SQL语言 查询语句基础 实验3

数据库与实验2相同 就不重复展示了

实验内容

1.查询C1课程的选课人数

select COUNT(*) as 人数 from SC where CNo='C1'

运行结果

2.查询程序设计课程的选课人数。结果列名为课程名、选课人数

select CN as 课程名,COUNT(*) as 选课人数 from SC,c where sc.CNo=c.CNo and CN='程序设计'
group by CN

运行结果

3.查询各门课程的选课人数、平均分、最高分、最低分、总分。结果列名为课程名、选课人数、平均分、最高分、最低分、总分

select CN as 课程名,COUNT(*) as 选课人数, AVG(score) as 平均分,MAX(score) as 最高分,
MIN(score) as 最低分, SUM(score) as 总分 from SC,c where sc.CNo=c.CNo
group by CN

运行结果

4.统计各系有多少人,用as让结果显示系名、人数

select s.dept as 系名,COUNT(*) as 人数 from s,t where s.Dept=t.Dept
group by s.dept

运行结果

5.统计各系有多少女生。用as让结果显示系名、性别、人数

select s.dept as 系名,s.Sex as 性别,COUNT(*) as 人数 from s,t where s.Dept=t.Dept and s.Sex='女'
group by s.dept,s.sex

运行结果

如需转载使用,请务必标明出处,谢谢

posted @ 2022-05-25 23:52  柏木カケル  阅读(160)  评论(0)    收藏  举报