本文由我司收集整编,推荐下载,如有疑问,请与我司联系
sql
语句
,
如何查询一个班的学生成绩都及格的学生的姓名
2011/03/09
10
where
成绩
60and........
关键是如何判断一个班的都及格
了??????????????????
select
班级,学生姓名
from
成绩表
where
成绩
60and
班级
notin(selectdistinct
班级
from
成绩表
where
成绩
60)
select*from
成绩表
twherenotexists(select1from
成绩表
wheret.
班级
=
班级
andt.
成绩
60)
select
班级
,sum(casewhen
成绩
=60then1else0end)
及格人数
,count(*)
总人数
from
成绩表
groupby
班级
withcteas(select
班级
,sum(casewhen
成绩
=60then1else0end)
及格
人数
,count(*)
总人数
from
成绩表
groupby
班级
)select
班级
,(casewhen
及格人数
总人
数
then’
不完全及格
’else’
全部及格
’end)
及格标识
fromcte
if(selectcount(0)from
成绩
表
)=(selectcount(0)from
成绩表
where
成绩
=60)print’
都及格了
’elseprint’
有人不及格
’
SQL
语句练习题参考答案
1
、
selectSname,Ssex,ClassfromStudent;2
、
selectdistinctdepartfromteacher;3
、
selectSnoas’
学号
’,Snameas’
姓名
’,Ssexas’
性
别
’,Sbirthdayas’
出生日期
’,Classas’
班号
’fromstudent;
或
selectSnoas
学号
,Snameas
姓
名
,Ssexas
性别
,Sbirthdayas
出生日期
,Classas
班号
fromstudent;4
、
select*fromscorewheredegreebetween60and80;
或
select*fromscorewheredegree
=60anddegree
5
、
select*fromscorewheredegreein(85,86,88);6
、
select*fromstudentwhere
orSsex=‘
女
’;7
、
select*fromstudentorderbyclassdesc;8
、
select*fromscoreorderbycnoasc,degreedesc;
或
select*fromscoreorderbycno,degreedesc;9
、
selectcount(*)asCNTfromstudentwhere
;10
、
selectSnoas’
学号
’,cnoas’
课程号
’,degreeas’
最高
分
’fromscorewheredegree=(selectmax(degree)fromscore)11
、
selectavg(degree)as
课程平
均分
fromscorewherecno=‘3-105’;12
、
selectcno,avg(degree)fromscorewherecnolike’3%’groupbycnohavingcount(*)
13
、
selectSnofromscoregroupbySnohavingmin(degree)
70andmax(degree)
14
、
selectstudent.Sname,score.Cno,score.degreefromstudent,scorewherestudent.Sno=score.Sno
;15
、
selectx.Sno,y.Cname,x.degreefromscorex,courseywherex.Cno=y.Cno;16
、