内容发布更新时间 : 2025/7/11 8:54:35星期一 下面是文章的全部内容请认真阅读。
选课表:SC Sno 9512101 9512103 9512101 9512103 9521101 9521102 9521103 9531101 9531102 9512101 9531102 9512101 9512101 Cno C03 C03 C05 C05 C05 C05 C05 C05 C05 C01 C01 C02 C04 Grade 95 51 80 60 72 80 45 81 94 NULL NULL 87 76
2、完成下列查询
(1)查询全体学生的信息。
select * from student
(2)查询“信息系”学生的学号,姓名和出生年份。
select Sno,Sname,2009-Sage as Birthyear from student where Sdept='信息系'
(3)查询考试不及格的学生的学号。
select Distinct Sno from SC where Grade<60
(4)查询无考试成绩的学生的学号和相应的课程号。
select Sno,Cno from SC where Grade is null
(5)将学生按年龄升序排序。
select * from student order by Sage asc
(6)查询选修了课程的学生的学号和姓名。
11
Select Sno,Sname from Student Where Sno in (Select Sno From Sc) 或:
select distinct student.Sno,Sname from student,SC where student.Sno=SC.Sno
(7)查询年龄在20-23岁之间的学生的姓名,系,年龄。
select Sname,Sage,Sdept from student where Sage between 20 and 23
(8)查询同时选修了“计算机导论”,“高等数学”课程的学生的学号,姓名。
select student.Sno,Sname from student where NOT EXISTS( select* from course where
Cname in('高等数学','计算机导论') AND NOT EXISTS(select * from SC where Sno=student.Sno and Cno=course.Cno)) 或:
select student.Sno,Sname from student,sc,Course where student.sno=sc.sno and sc.cno=course.cno and cname='高等数学' and student.sno in (select sno from sc where cno=(select cno from course where cname='计算机导论')) 或:
select student.Sno,Sname from student where sno in (select sno from sc where cno=(select cno from course where cname='高等数学')) and sno in (select sno from sc where cno=(select cno from course where cname='计算机导论'))
(9)查询姓“张”的学生的基本信息。
select * from student where Sname like '张%'
(10)查询“95211”班学生