数据库——数据查询

查询所在系为 “CS” 的学生学号和姓名;

select sno,sname

from student

where sdept='cs';

2. 查询选修了3号课程的学生学号;

select sno

from sc

where cno='3';

3. 查询选修1号 课程的学生学号和成绩,并要求对查询结果按成绩的降序排列,如果成绩相同则按学号的升序排列;(P96 order by语句)

select sno,grade

from sc

where cno='1'

order by grade desc,sno asc;

4.  查询选修课程1号课程且成绩在80-90 之间的学生学号和成绩,并将成绩乘以系数0.75 输出;

select sno,grade*0.75

from sc

where cno='1' and grade  between 80 and 90;

5. 查询所在系为 “CS”或者“MA”的姓张的学生信息;P95

select *

from student

where sname like'张%' and sdept='cs' or sdept='ma';

6.  查询缺少了成绩的学生的学号和课程号。P96

select sno,cno

from sc

where grade is null;

7. 查询每个学生的学号,姓名,选修的课程名,成绩;

select student.sno,sname,cname,grade

from sc,student,course

where student.sno=sc.sno and sc.cno=course.cno;

查询选修1号课程且成绩在90 分以上的学生学号、姓名及成绩;

select student.sno,sname,grade

from sc,student

where student.sno=sc.sno and cno='1' and grade>90;

查询每门课程的先行课程的课程名称,学分;

select cpno,ccredit

from course

查询每一门课的间接先行课的课程编号P102

select first.cno,second.cpno

from course first,course second

where first.cpno=second.cno;

猜你喜欢

转载自blog.csdn.net/hml666888/article/details/80964090