查詢沒有學全所有課程同學的姓名,學號。

2021-10-03 02:03:29 字數 630 閱讀 4797

1、查詢所有的課程數:

select count(cno) as zs from course;-- zs:總課程數的列名

2、查出學生學的課程數、學號姓名:

select s.sno,s.sname,count(sc.cno) as zs1 from sc,student s where sc.sno=s.sno group by sc.sno; – zs1:學生學課程數的列名

3、根據上邊的查詢,寫出最終答案:

select b.sno,b.sname from (

select count(cno) as zs from course

)a,(

select s.sno,s.sname,count(sc.cno) as zs1 from sc,student s where sc.sno=s.sno group by sc.sno

) bwhere a.zs=b.zs1;

4、字段解釋:

course:課程表(字段:cno,cname)

student:學生表(字段:sno,sname)

sc:成績表(字段:sno,score,cno)

cno:班級編號。

count():統計

group by:分組

SQL查詢選修了所有課程的學生姓名

select sname from student where not exists select from course where not exists select from sc where sno student.sno and cno course.cno 最內部的 select fro...

求出選修了所有課程的學生姓名

求出選修了所有課程的學生姓名 學生表 s sno int pk,sn varchar 8 sno為學號 sn為學生姓名。課程表 c cno int pk,cn varchar 50 cno為課程號,cn為課程名 選修表 sc sno int pk,cno int pk,score number 7,...

查詢選修了全部課程的學生姓名

select sname from student where not exists select from course where not exists select from sc where sno student.sno and cno course.cno 我的理解是 這是乙個相關子查詢...