1、表结构
学生表Student(学号Sno、Sname姓名、Ssex性别、Sage年龄、所在系Sdept)
课程表Course(Cno课程号、Cname课程名、Cpon先行课、Ccredit学分)
选课表SC(学号Sno、Cno课程号、Grade分数)
2、查询
select * from Student a
select * from Course b
select * from SC c
----查询每个学生的平均分、课程数
select a.Sno ,avg(c.Grade)as 'score',COUNT(c.Cno)as 'kcnum' from dbo.Student a
join
dbo.SC c on a.Sno=c.Sno
group by a.Sno
---查询平均分大于70的学生、课程数
select a.Sno ,avg(c.Grade)as 'score',COUNT(c.Cno)as 'kcnum' from dbo.Student a
join
dbo.SC c on a.Sno=c.Sno
group by a.Sno
having avg(c.Grade)>70
---查询没有学课的学生(not in和not EXISTS两种写法 )
select * from Student a where Sno not in (select Sno from SC c )
select * from Student a whe