–1.查询各位学生的学号、班级和姓名
select SNo,Class,SN
from S
–2.查询课程的全部信息
select *
from C
–3.查询数据库中有哪些专业班级
select distinct Class
from S
–4.查询学时数大于60课程信息
select *
from C
where CT>60
–5.查询在1986年出生的学生的学号、姓名和出生日期
select SNo,SN,birthday
from S
where datename(year,birthday)=1986
–6.查询三次作业的成绩都在80分以上的学号、课程号
select SNo,CNo
from SC
where Score_1>=80 and Score_2>80 and Score_3>80
–7.查询姓张的学生的学号、姓名和专业班级
select SNo,SN,Class
from S
where SN like '张%'
–8.查询05级的男生信息
select *
from S
where right(Class,2)=05 and Sex='男'
–9.查询没有作业成绩的学号和课程号
select SNo,CNo
from SC
where Score_1 is null or Score_2 is null or Score_3 is null
–10.查询学号为1538的学生的作业1总分
select sum(Score_1) as 总分
from SC
where SNo=1538
–11.查询选修了K001课程的学生人数
select count(SNo) as 选课人数
from SC
where CNo='K001'
–12.查询数据库中共有多少个班级
select count(distinct Class) as 班级数量
from S
–13.查询选修三门以上(含三门)课程的学生的学号和作业1平均分、作业2平均分和作业3平均分
select SNo,avg(Score_1) 作业1平均分,avg(Score_2) 作业2平均分,avg(Score_3) 作业3平均分
from SC
group by SNo
having count(CNo)>=3
–14.查询于兰兰的选课信息,列出学号、姓名、课程名(使用两种连接查询的方式)
select S.SNo,SN,CN
from S,C,SC
where S.SNo=SC.SNo and SC.CNo=C.CNo and SN='于兰兰'
select R4.SNo,R4.SN,R3.CN
from
(select CNo,CN from C) as R3
inner join
(select R1.SNo,R1.SN,R2.CNo
from
(select SNo,SN from S where SN='于兰兰') as R1
inner join
(select CNo,SNo from SC) as R2
on R1.SNo=R2.SNo) as R4
on R3.CNo=R4.CNo
|