用SQL语句完成以下查询
1. 查询所在系为 “CS” 的学生学号和姓名;
select sno,sname
fromstudent
where sdept='CS';
2. 查询选修了3号课程的学生学号;
select sno
from SC
where cno=3;
3. 查询选修1号 课程的学生学号和成绩,并要求对查询结果按成绩的降序排列,如果成绩相同则按学号的升序排列;
select sno,grade
from SC
where cno='1'
orderby grade desc,sno;
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”的姓张的学生信息;
select*
fromstudent
where (sdept='CS'or sdept='MA')and sname like'张%';
6. 查询缺少了成绩的学生的学号和课程号。
select sno,cno
from SC
where grade isNULL;
7. 查询每个学生的学号,姓名,选修的课程名,成绩;
selectstudent.sno,sname,cname,grade
fromstudent,course,SC
where student.sno=SC.sno and SC.cno=course.cno;
8. 查询学生的学号、姓名、选修的课程名及成绩;
select student.sno,sname,cname,grade
from student,course,SC
where student.sno=SC.sno and SC.cno=course.cno;
9. 查询选修1号课程且成绩在90 分以上的学生学号、姓名及成绩;
selectstudent.sno,sname,grade
fromstudent,SC
where student.sno=SC.sno and cno='1'and grade>90;
10. 查询每门课程的先行课程的课程名称,学分;
selectcname,ccredit
fromcourse
where cpno isNULL;
11. 查询每一门课的间接先行课的课程编号
selectfirst.cno
fromcourse first,coursesecond
wherefirst.cpno=second.cno;
12. 查询每一门课的间接先行课的课程名称;
selectfirst.cname
fromcourse first,coursesecond
wherefirst.cpno=second.cno;
13. 查询所在系部为“MA”且选修了高等数学课程的学生姓名,年龄,性别;
selectsname,sage,ssex
from student,course
where sdept='MA'and cno=2;
14. 查询选修了数据结构课程,且成绩在90分以上的学生学号;
selectstudent.sno
fromstudent,course,SC
where student.sno=SC.sno and SC.cno=course.cno and course.cname=’数据结构’and grade>90;
15. 查询选修了数据结构课程,且成绩在90分以上的学生姓名,年龄;
selectsname,sage
from student,course,SC
where student.sno=SC.sno and SC.cno=course.cno and cname='数据结构'and grade>90;
16. 查询选修了数据结构课程的学生学号,姓名,成绩;
selectstudent.sno,sname,grade
fromstudent,course,SC
where student.sno=SC.sno and SC.cno=course.cno and cname='数据结构';
17. 查询所在系部为“MA”的女生人数;
selectcount(sno)
fromstudent
where sdept='MA'and ssex='女';
18. 查询选修了2号课程的学生姓名;
selectsname
fromstudent
whereexists
(select*
from SC
where sno=student.sno and cno='2');
19. 查询没有选修2号课程的学生姓名;
selectsname
fromstudent
wherenotexists
(select*
from SC
where sno=student.sno and cno='2');
20. 查询选修了全部课程的学生的姓名;
selectsname
fromstudent
wherenotexists
(select*
fromcourse
wherenotexists
(select*
from SC
where sno=student.sno
and cno=course.cno));
21. 查询至少选修了学号为“201215121”的学生所选修的全部课程的学生学号和姓名;
selectdistinct SCX.sno,sname
from SCSCX,student
where SCX.sno=student.sno andnotexists
(select*
from SC SCY
where SCY.sno='201215121'and
notexists
(select*
from SCSCZ
where SCZ.sno=SCX.sno
and SCZ.cno=SCY.cno));
22. 查询学生的总人数;
selectcount(*)
from student;
23. 查询每个系部的学生人数;
selectcount(sdept)as x,sdept
fromstudent
groupby sdept;
24. 查询选修了1号课程的学生人数;
selectcount(cno)as x
from SC
where cno='1';
25. 查询选修了操作系统课程的学生人数;
selectcount(cname)as x
fromstudent,SC,course
wherestudent.sno=SC.sno and SC.cno=course.cno
and cname='操作系统';