一
(1)查询零件重量在10-20之间(包括10和20)的零件名和颜色。
select pname,color
from p
where weight>=10 and weight<=20;
(2)查询所有零件的平均重量。
select avg(weight)
from p;
(3)查询供应商s3供应的零件信息。
select *
from spj
where sno='s3';
(4)查询各个供应商号及其供应了多少类零件。
select sno,count(pno)
from spj
group by sno;
(5)查询供应了2类以上零件的供应商号。
select sno
from spj
group by sno
having count(pno)>2;
(6)查询零件名以“螺”字开头的零件信息。
select *
from p
where pname like '螺%';
(7)查询给每个工程供应零件的供应商的个数。
select jno,count(sno)
from spj
group by jno;
(8)查询供应总量在1000—2000之间(包括1000和2000)
的零件名称。
select pname
from p
where pno in
(select pno
from spj
group by pno
having sum(qty)>=1000 and sum(qty)<=2000);
二
(1)查询所有课程的课程名,课程性质,学分和学时属性列,
要求在查询结果中用中文重新命名属性列的列名。
select cname as 课程名,cproperty as 课程性质,credit as 学分,
chour as 学时
from course;
(2)查询学生所在专业的专业名包含“大数据”三个字的所有学生学号
,姓名、专业名和所在学院。
select sno,sname,scollege,smajor
from student
where smajor like '%大数据%';
(3)查询“计算机科学与技术”专业学生的姓名和年龄。
(年龄属性列需要计算得到)
select sname,to_char(sysdate,'yyyy')-to_char(sbirth,'yyyy') sage
from student
where smajor='计算机科学与技术';
(4)查询“软件工程”专业1995年出生的学生信息,查询结果按学生出
生的时间先后排序。
select *
from student
where smajor='软件工程' and to_char(sbirth,'yyyy')='1995'
order by sbirth ;
(5)查询每门课程的修课人数和考试最高分,列出课程号,选修课程
人数和该课程的最高成绩。
select cno,count(cno),max(grade)
from sc
group by cno;
(6)查询课程性质是选修,并且选修人数在60人以上的课程名、课程
学时和开设学期。
select cname,chour,cterm
from course
where cproperty='选修' and cno in(
select cno
from sc
group by cno
having count(sno)>60);
(7)统计每个学院的学生人数。
select scollege,count(sno)
from student
group by scollege;
(8)查询信息工程学院所有学生已修课程的总学分,要求列出学号、
姓名和总学分。
select student.sno,sname,sum(credit)
from student,sc,course
where student.sno=sc.sno and course.cno=sc.cno and scollege='信息工程学院'
group by student.sno,sname;
(9)查询吴春燕老师所授课程的选课和成绩信息,要求列出该老师所
授课程的课程名,选课的学生姓名和课程成绩。
select sname,grade
from student,sc,course
where student.sno=sc.sno and sc.cno=course.cno and course.cno in
(select course.cno
from course,teacher,tc
where course.cno=tc.cno and tc.tno=teacher.tno and tname='吴春燕');
(10)查询同时选修了“中间件技术”和“Java EE技术”两门选修课的学
生学号。
select sno
from sc
where cno in
(select c1.cno
from course c1,course c2
where c1.cname='中间件技术' and c2.cname='Java EE技术');
(11)查询1994年1月1日以前出生的学生的姓名和专业。
select sname,smajor
from student
where to_number(to_char(sysdate,'yyyy')-to_char(sbirth,'yyyy'))>30;
(12)查询选修了5门以上课程的学生学号和姓名。
select sc.sno,sname
from student,sc
where student.sno=sc.sno
group by sc.sno,sname
having count(cno)>5;
(13)查询比本院学生平均年龄小的学生信息,要求列出姓名与年龄。
select sname,to_char(sysdate,'yyyy')-to_char(sbirth,'yyyy') age
from student s1
where to_char(sysdate,'yyyy')-to_char(sbirth,'yyyy')<
(select avg(to_char(sysdate,'yyyy')-to_char(sbirth,'yyyy'))
from student s2
where s1.scollege=s2.scollege
group by scollege);
(14)查询一门课也没有带的教师姓名。
select Tname
from Teacher
where not exists
(select *
from tc
where teacher.tno=tc.tno);
(15)查询比所有“计算机科学与技术”专业学生年龄都大的学生。
select *
from student
where to_char(sysdate,'yyyy')-to_char(sbirth,'yyyy')>all
(select to_char(sysdate,'yyyy')-to_char(sbirth,'yyyy')
from student
where smajor='计算机科学与技术');