赞
踩
文章目录
7、查询非计算机科学系中比计算机学科系所有学生年龄都小的学生姓名和年龄
10、在 SC表中查询至少选修了1号学生选修的全部课程的学生的学号
17、统计每个同学选修及格的课程的平均分,列出其学号、姓名及平均分。
19、查询选修了C1和C2课程,并且成绩均大于85分的同学的学号、课程号以及成绩
28、查询至少选修了2020003号学生所选的全部课程的学生的学号与姓名
- SELECT Sno
- FROM SC
- GROUP BY Sno
- HAVING COUNT(Cno)>3;
- SELECT Sno
- FROM SC
- WHERE Sno NOT IN
- (SELECT Sno
- FROM SC
- WHERE Grade >70)
- UNION
- SELECT Sno
- FROM SC
- WHERE Grade>70
- GROUP BY Sno
- HAVING count(Cno)=1 ;
- SELECT Sno,avg(Grade)
- FROM SC
- GROUP BY Sno
- HAVING avg(Grade)>=90;
- SELECT distinct Sno
- FROM SC
- WHERE Grade NOT IN(
- SELECT Grade
- FORM SC
- WHERE Grade<=70);
- SELECT Sno,Cno
- FROM SC X
- WHERE Grade>=(
- SELECT avg(grade)
- FROM SC Y
- WHERE Y.Sno=X.Sno);
- SELECT Sname,Sage
- FROM student
- WHERE Sage<ANY(
- SELECT Sage
- FROM Student
- WHERE Sdept='CS')
- AND Sdept <>'CS';
- SELECT Sname,Sage
- FROM student
- WHERE Sage<ALL(
- SELECT Sage
- FROM Student
- WHERE Sdept='CS')
- AND Sdept <>'CS';
- 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 Sname
- FROM Student
- WHERE EXISTS(
- SELECT *
- FROM SC
- WHERE SC.Sno=Student.Sno AND Cno='1');
- SELECT DISTINCT SnO
- FROM SC SCX
- WEHRE NOT EXISTS
- (SELECT *
- FROM SC SCY
- WHERE SCY.SnO='1' AND NOT EXISTS
- (SELECT *
- FROM SC SCZ
- WHERE SCZ.Sno=SCX.Sno AND SCZ.Cno=SCY.Cno)
- );
- SELECT Sno,Cno
- FROM SC,(SELECT Sno,avg(Grade)
- FROM SC
- GROUP BY Sno) AS avgsc(avgsno,avggrade);
- WHERE SC.Sno=avgsc.avgsno AND SC.Cno>avgsc.avggrade;
- 或
- SELECT Sno,Cno
- FROM SC x
- WHERE Grade>=(SELECT avg(Grade)
- FROM SC y
- WHERE y.Sno=x.Sno);
- SELECT Sname
- FROM Student,(SELECT Sno
- FROM SC
- WHERE Cno='1') AS SC1
- WHERE Student.Sno=SC1.Sno;
- select SC.Sno,Sname,Cname,Grade
- from SC,Course,Student
- where SC.Cno=Course.Cno and Student.Sno=SC.Sno
- select SC.Cno,Course.Cname,count(Sno)
- from SC, Course
- where SC.Cno=Course.Cno
- group by SC.Cno,Course.Cname
- select SC.Sno,Sname,count(Cno)
- from SC,Student
- where SC.Sno=Student.Sno
- group by SC.Sno,Sname
- select distinct SC.Cno,Cname
- from SC,Course,Student
- where SC.Cno=Course.Cno and Student.Sno=SC.Sno and Sname like '张%'
- select SC.Sno,Sname,avg(Grade)
- from SC,Student
- where SC.Sno=Student.Sno and Grade>60
- group by Sname,SC.Sno
- select SC1.Sno,SC1.Grade Grade1,SC2.Grade Grade2
- from SC SC1,SC SC2
- where SC1.Sno=SC2.Sno and SC1.Cno='81001' and SC2.Cno='81002'
- select SC1.Sno,SC1.Cno Cno1,SC2.Cno Cno2,SC1.Grade Grade1,SC2.Grade Grade2
- from SC SC1,SC SC2
- where SC1.Sno=SC2.Sno and SC1.Cno='1' and SC2.Cno='2' and SC1.Grade>85 and SC2.Grade>85
- select Course1.Cno,Course2.Cpno
- from Course Course1,Course Course2
- where Course1.Cpno=Course2.Cno
- select S2.Sno,S2.Sname
- from Student S1,Student S2
- where S1.Smajor=S2.Smajor and S1.Sno='20180002'
- select Student.Sno,Sname
- from Student,SC,Course
- where SC.Sno=Student.Sno and SC.Cno=Course.Cno and Course.Cname='数据库'
- select Sno,Sname
- from Student
- where Sdept in (
- select Sdept
- from Student
- where Sname='李四'
- )
- select distinct SC.Sno,Sname
- from SC,Student
- where SC.Sno=Student.Sno and SC.Grade >70
- 或者
- select distinct Sno,Sname
- from Student
- where exists (
- select*
- from SC
- where Student.Sno=SC.Sno and SC.Grade>70
- )
- select SC.Sno
- from SC,(
- select Sno
- from SC
- where Cno='1'
- ) S1
- where S1.Sno=SC.Sno and SC.Cno='2';
- 或者
- select SC1.Sno
- from SC SC1
- where exists (
- select *
- from SC SC2
- where SC1.Sno=SC2.Sno and SC1.Cno='1' and SC2.Cno='2'
- )
- select distinct SC1.Sno
- from SC SC1
- where not exists(
- select *
- from SC SC2
- where SC1.Sno=SC2.Sno and (SC2.Grade<70 or SC2.Grade is null)
- )
- select Sname
- from Student
- where not exists(
- select *
- from Course
- where not exists(
- select *
- from SC
- where SC.Sno=Student.Sno and SC.Cno=Course.Cno
- )
- )
- select distinct SCx.Sno,Sname
- from SC SCx,Student
- where SCx.Sno=Student.Sno and not exists(
- select *
- from SC SCy
- where SCy.Sno='2020003' and not exists(
- select *
- from SC SCz
- where SCz.Sno=SCx.Sno and SCz.Cno=SCy.Cno
- )
- )
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。