SQL代码:
--查询选修课程名称为’税收基础’的学员学号和姓名
Select SN,SD FROM S Where [S#]
IN( Select [S#]
FROM C,SC
Where C.[C#]=SC.[C#]
AND CN=N'税收基础'
)
--查询选修课程编号为’C2’的学员姓名和所属单位?
select sn,sd
from s,sc
where s.s#=sc.s#
and sc.c#=’c2’
-- (3) 使用标准SQL嵌套语句查询不选修课程编号为’C5’的学员姓名和所属单位?
select sn,sd from s,sc where s#
not in(select s# from sc where c#=’c5’)
--(4)列出有二门以上(含两门)不及格课程的学生姓名及其平均成绩
select s.sn,avg(sc.g)
from s,c
where s.`S#`=sc.`S#`
group by s.SN
having count(case when s.g<60 then 1 end )>2
-- (5)查询选修了课程的学员人数
select 学员人数=count(distinct s#) from sc
--(6) 查询选修课程超过5门的学员学号和所属单位?
select sn,sd from s
where s#
in(
select s#
from sc
group by s#
having count(distinct c#)
>5
)