select count([学号]) as [总人数]
from Studentclass
--2、查询选修了3号课程的学生姓名
select [姓名] from Student
where [学号] in (select [学号] from Studentclass where [课程号] = 3)
--3、查询学生“张三”的学号,姓名,选修课程名,成绩(第二张表的学分应该是成绩吧)
select a.[学号],a.[姓名],c.[课程名],b.[成绩]
from Student a,Studentclass b,Class c
where a.[学号] = b.[学号] and b.[课程号] = c.[课程号] and a.[姓名] = N'张三'
--4、查询选修课程“人工智能”的学生的学号,姓名
select a.[学号],a.[姓名]
from Student a
left join Studentclass b
on a.[学号] = b.[学号]
left join Class c
on b.[课程号] = c.[课程号]
where c.[课程名] = N'人工智能'
--5、查询选修1号课程的最高分是多少是哪个学生获得的
select [姓名]
from Studentclass
where [学号] in (select [学号] from Studentclass where [成绩] = (select max([成绩]) from Studentclass where [课程号] = 1))
--6、查询姓名中第二个字为“三”的学生列表
select [姓名] from Student where [姓名] like N'_三%'
--7、统计每个课程号对应的选课人数是多少
select [课程号],count([学号]) as [选课人数] from Studentclass group by [课程号]
--8、查询选修3号课程且成绩在70分以上的学生信息
select * from Student
where [学号] in (select [学号] from Studentclass where [课程号] = 3 and [成绩] >= 70)
--9、查询“化学系”的学生来自哪些省市
select [省区] from Student
where [系别] = N'化学系'
--10、查询全体学生情况,结果按所在系升序排列,同一系再按年龄降序排列
select * from Student order by [系别],[年龄] desc
--11、查询选修了4号课程的平均成绩
select avg([成绩]) from Studentclass group by [课程号] having [课程号] = 4
--12、把3号课程学分<60分的数据更新为60
update Studentclass
set [学分] = 60
where [学分] <60 and [课程号] = 3
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)