lab3-select基础

1.查询全部课程的详细记录;

1
select * from COURSES;

image-20210913154224368

2.查询所有有选修课的学生的编号;

1
select distinct sid from choices;

image-20210913154237512

3.查询课时<88(小时)的课程的编号;

1
select cid from COURSES where hour < 88;

image-20210913154302007

4.请找出总分超过400分的学生;

1
2
3
select sid from CHOICES
group by sid
having SUM(isnull(score,0)) > 400;

image-20210913155332086

5.查询课程的总数;

1
select COUNT(cid) from COURSES;

image-20210913143709063

6.查询所有课程和选修该课程的学生总数;

1
2
3
4
select  cname,count(sid) as student_cnt
from COURSES c ,choices ch
where c.cid = ch.cid
group by cname;

image-20210913144731761

7.查询选修成绩超过60的课程超过两门的学生编号;

1
2
3
4
5
select sid 
from CHOICES
where score > 60
group by sid
having COUNT(cid)>2;

image-20210913145328293

8.统计各个学生的选修课程数目和平均成绩;

1
2
3
select  sid, COUNT(cid) as coursesnum, AVG(isnull(score,0)) as avg_score 
from CHOICES
group by sid;

image-20210913155200818

9.查询选修Java的所有学生的编号及姓名;

1
select  distinct s.sid as studetn_id, snamefrom students s ,COURSES c ,choices chwhere s.sid = ch.sid and c.cid = ch.cid and cname = 'java';

image-20210913153301386

10.查询姓名为sssht的学生所选的课程的编号和成绩;

1
select  cid,scorefrom students s ,choices chwhere sname = 'sssht' and s.sid = ch.sid  ;

image-20210913150654296

11.查询其他课时比课程C++多的课程的名称;

1
select  c2.cnamefrom COURSES c1, COURSES c2where c1.cname = 'c++' and c2.hour > c1.hour;

image-20210913151619265


lab3-select基础
https://wuhlan3.gitee.io/2021/09/13/lab3-select基础/
Author
Wuhlan3
Posted on
September 13, 2021
Licensed under