:查所有年龄在20岁以下的学生姓名及年龄。
Select name,age from student where age<=20;
2:查考试成绩有不及格的学生的学号
Select numbers from student where socor <=60;
3:查所年龄在20至23岁之间的学生姓名、系别及年龄。
Select name,xi,age from student where between 20 and 23
4:查计算机系、数学系、信息系的学生姓名、性别。
Select name,sex from student where comperter,math,information
5:查既不是计算机系、数学系、又不是信息系的学生姓名、性别
Select name sex from student where sd not in(‘ji’,’math’,’information’)
6:查所有姓“刘”的学生的姓名、学号和性别。
Select name,numbers,sex from student where name=’刘’
7:查姓“上官”且全名为3个汉字的学生姓名。
Select name from student where name like ‘上官_’;
8:查所有不姓“张”的学生的姓名。
select name from student where name not like '张%'
9:查DB_Design课程的课程号。
Select numbers from student where name like ‘DB\_Design’
10:查缺考的学生的学号和课程号。
Select name from student where not exists;
11:查年龄为空值的学生的学号和姓名。
Select 学号,姓名 from student where is null;
12:查计算机系20岁以下的学生的学号和姓名。
Select numbers and name from student where ji ‘ s age <=20;
13:查计算机系、数学系、信息系的学生姓名、性别。
Select name,sex from student where ji,math.information;
14:查询选修了C3课程的学生的学号和成绩,其结果按分数的降序排列。
SELCET 学号,姓名,课程号,成绩 FROM 学生表 ORDER BY 课程名 ASC
15:查询结果按所在系升序排列,对同一系中的学生按年龄降序排列。
select * from (表名) order by 班级号 asc,年龄 desc
#16:查询学生总人数。
SELECT count(sno) from s
#17:查询选修了课程的学生人数。
SELECT count(DISTINCT(sno)) from sc where cno is not null
#18:计算选修了php的学生平均成绩。
SELECT AVG(grade) from sc,c where sc.cno = c.cno and cname='php'
#19:查询学习php课程的学生最高分数。
SELECT max(grade) from sc,c where sc.cno = c.cno and cname='php'
#20:查询各个课程号与相应的选课人数。
SELECT cno,COUNT(sno) from sc GROUP BY cno
#查询计算机系选修了3门以上课程的学生的学号。
#SELECT s.sno from s,sc where s.sno = sc.sno and sdept='1506' HAVING COUNT(cno)>3
#:求基本表S中男同学的每一年龄组(超过50人)有多少人?要求查询结果按人数升序排列,人数相同按年龄降序排列。
#SELECT COUNT(sno) as num from s where ssex='男' GROUP BY sage HAVING num>50 ORDER BY num ASC,sage desc
#SELECT COUNT(sno) as num from s where ssex='男' GROUP BY sage HAVING num>50
#查询每个学生及其选修课程的情况。
#SELECT * from s,sc,c where s.sno = sc.sno and sc.cno = c.cno
#查询选修了php课程且成绩在90分以上的所有学生。
SELECT * from s,sc,c where s.sno = sc.sno and sc.cno = c.cno and cname='php' and grade>90
#25:查询每个学生选修的课程名及其成绩。
SELECT sname,cname,grade from s,sc,c where s.sno = sc.sno and sc.cno = c.cno
#26:统计每一年龄选修课程的学生人数。
SELECT sage,COUNT(DISTINCT s.sno) from s,sc where s.sno = sc.sno GROUP BY sage
27:查询选修了php课程的学生姓名。
28:查询与“张三”在同一个系学习的学生学号、姓名和系别。
SELECT sno,sname,sdept from s where sdept=(SELECT sdept from s where sname='张四')
#30:查询所有未选修C2课程的学生姓名。
SELECT sname FROM s WHERE NOT EXISTS ( SELECT * FROM sc WHERE sno = s.sno AND cno = 2 )
31:查询选修了全部课程的学生姓名。
SELECT sname FROM s WHERE NOT EXISTS (SELECT * FROM c WHERE NOT EXISTS ( SELECT * FROM sc WHERE sc.sno = s.sno AND sc.cno = c.cno ) ) ;
#32:查询所学课程包含学生S3所学课程的学生学号
SELECT DISTINCT sno FROM sc AS X WHERE NOT EXISTS ( SELECT * FROM sc AS Y WHERE Y.Sno =‘S3’AND NOT EXISTS ( SELECT * FROM sc AS Z WHERE Z.sno = X.sno AND Z.cno = Y.cno ) ) ;
https://wenku.baidu.com/view/558dc43276eeaeaad0f33054.html?qq-pf-to=pcqq.c2c