SQL经典练习题48道之三(20-25)

接上篇SQL经典练习题48道之二(11-19)
20、假设使用如下命令建立了一个grade表:
create table grade(low int,upp int,rank char(1));
insert into grade values(90,100,’A’);
insert into grade values(80,89,’B’);
insert into grade values(70,79,’C’);
insert into grade values(60,69,’D’);
insert into grade values(0,59,’E’);
现查询所有同学的Sno、Cno和rank列。
答:
select sno,cno,degree,rank from score s left join grade g on s.degree>=g.low and s.degree<=g.upp;
21、查询选修“3-105”课程的成绩高于“109”号同学成绩的所有同学的记录。
答:
select * from score where cno=’3-105’ and degree > (select degree from score where sno=’109’ and cno=’3-105’);
22、查询score中选学一门以上课程的同学中分数为非最高分成绩的记录。
答:
select count(1) from score s1 where degree <(select max(s2.degree) from score s2 where s2.cno=s1.cno) and cno in (select cno from score group by cno having count(*)>1);
23、查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。
答:
select * from score where degree >(select degree from score where sno=’109’ and cno=’3-105’);
24、查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。
答:
select sno,sname,sbirthday from student where sno!=’108’ and date_format(sbirthday,’%Y’) =( select date_format(sbirthday,’%Y’) from student where sno=’108’);
25、查询“张旭“教师任课的学生成绩。
答:
select * from score where cno in (select cno from course c right join teacher t on t.tno=c.tno where t.tname=’张旭’);

猜你喜欢

转载自blog.csdn.net/u014332200/article/details/80582782