Student(student_id,student_name,student_age,student_sex) 学生表
Course(Course_id,course_name,Teacher_id) 课程表
SC(student_id,Course_id,score) 成绩表
Teacher(Teacher_id,teacher_name) 教师表
答案不知道有没有错,有时间再来修改
问题:
1、查询“001”课程比“002”课程成绩高的所有学生的学号;
select a.student_id from
(select student_id,score from SC where Course_id='001') a,
(select student_id,score from SC where Course_id='002') b
where a.score>b.score and a.student_id=b.student_id;
2、查询平均成绩大于60分的同学的学号和平均成绩;
select student_id,avg(score)
from sc
group by student_id having avg(score) >60;
3、查询所有同学的学号、姓名、选课数、总成绩;
select Student.student_id,Student.student_name,count(SC.Course_id),sum(score)
from Student left join SC on Student.student_id=SC.student_id
group by Student.student_id,student_name
4、查询姓“李”的老师的个数;
select count(distinct(teacher_name)) from Teacher where teacher_name like '李%';
5、查询没学过“叶平”老师课的同学的学号、姓名;
select Student.student_id,Student.student_name
from Student
where student_id not in (
select distinct(SC.student_id) from SC,Course,Teacher
where SC.Course_id=Course.Course_id
and Teacher.Teacher_id=Course.Teacher_id
and&acher_name='叶平'
);
6、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名;
select Student.student_id,Student.student_name
from Student,SC
where Student.student_id=SC.student_id and SC.Course_id='001'and exists(
Select * from SC as SC_2
where SC_2.student_id=SC.student_id and SC_2.Course_id='002'
);
7、查询学过“叶平”老师所教的所有课的同学的学号、姓名;
select student_id,student_name
from Student
where student_id in (
select student_id
from SC ,Course ,Teacher
where SC.Course_id=Course.Course_id and Teacher.Teacher_id=Course.Teacher_id and&acher_name='叶平' group by student_id having count(SC.Course_id)=(
select count(Course_id) fromCourse,Teacher
where Teacher.Teacher_id=Course.Teacher_id and teacher_name='叶平')
);
8、查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、姓名;
Select student_id,student_name from
(select Student.student_id,Student.student_name,score ,
(select score from SC SC_2 where SC_2.student_id=Student.student_id and SC_2.Course_id='002') score2
from Student,SC where Student.student_id=SC.student_id and Course_id='001') S_2 where score2 <score;
9、查询所有课程成绩小于60分的同学的学号、姓名;
select student_id,student_name
from Student
where student_id not in (
select Student.student_id from Student,SC
where S.student_id=SC.student_id and score>60);
10、查询没有学全所有课的同学的学号、姓名;
select Student.student_id,Student.student_name
from Student,SC
where Student.student_id=SC.student_id
group by Student.student_id,Student.student_name
having count(Course_id) <(select count(Course_id) from Course
);
11、查询至少有一门课与学号为“1001”的同学所学相同的同学的学号和姓名;
select student_id,student_name
from Student,SC
where Student.student_id=SC.student_id and Course_id in(
select Course_id from SC where student_id='1001'
);
12、查询至少学过学号为“001”同学所有一门课的其他同学学号和姓名;
select distinct SC.student_id,student_name
from Student,SC
where Student.student_id=SC.student_id and Course_id in (
select Course_id from SC where student_id='001'
本文发布于:2024-02-04 19:49:00,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170715136159005.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |