周测代码

Posted pan520

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了周测代码相关的知识,希望对你有一定的参考价值。

一.表名和字段

–1.学生表

Student(s_id,s_name,s_birth,s_sex) --学生编号,学生姓名, 出生年月,学生性别

–2.课程表

Course(c_id,c_name,t_id) – --课程编号, 课程名称, 教师编号

–3.教师表

Teacher(t_id,t_name) --教师编号,教师姓名

–4.成绩表

Score(s_id,c_id,s_score) --学生编号,课程编号,分数

1、查询"01"课程比"02"课程成绩高的学生的信息及课程分数

Select s_name as 学生姓名,s_score as 学生成绩

From student as s

Inner join score as sc on s.s_id=sc.s_id

Where select s_score from score where c_id=’01’>(select s_score from score where c_id=’02’)

2、查询"01"课程比"02"课程成绩低的学生的信息及课程分数

Select s_name as 学生姓名,s_score as 学生成绩

From student

From student as s

Inner join score as sc on s.s_id=sc.s_id

Where select s_score from score where c_id=’01’<(select s_score from score where c_id=’02’)

3、查询平均成绩大于等于60分的同学的学生编号和学生姓名和平均成绩

Select s.s_id as 学生ids_name as 学生姓名,avg(sc.s_score)as 学生成绩

From student as s

Inner join score as sc

On s.s_id=sc,s_id

Where avg(sc.score)>60

4、查询平均成绩小于60分的同学的学生编号和学生姓名和平均成绩

-- (包括有成绩的和无成绩的)

Select s.s_id as 学生ids_name as 学生姓名,avg(sc.s_score)as 学生成绩

From student as s

Inner join score as sc

On s.s_id=sc,s_id

Where avg(sc.score)<60

5、查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩

Select s.s_id as 学生编号,s.s_name as 学生姓名,count(sc.c_id)as 选课总数,sumsc.s_scoreas 所有课程的总成绩

From stuednt as s

Inner join score sc on s.s_id=sc,s_id

Group by s.s_id

6、查询"李"姓老师的数量 

select count(t_name)as 李姓老师的数量

From teacher

Where t_name like ‘%’

7、查询学过"张三"老师授课的同学的信息

Select*

From student

Where s_id in(

select t_id from teacher as t

inner join course as c on t.t_id=c.t_id

inner join score as s on s.c_id=c.c_id

where t_name=’张三’)

8、查询没学过"张三"老师授课的同学的信息

Select*

From student

Where s_id not in(

select s.s_id from teacher as t

inner join course as c on t.t_id=c.t_id

inner join score as s on s.c_id=c.c_id

where t_name=’张三’)

9、查询学过编号为"01"并且也学过编号为"02"的课程的同学的信息

Select*

From student

Where s_id in(select c_id from score where c_id=’01’ and c_id=’02’)

10、查询学过编号为"01"但是没有学过编号为"02"的课程的同学的信息

Select*

From student

Where s_id in(select s_id from score where c_id=’01’ and c_id!=’02’)

11、查询没有学全所有课程的同学的信息 

Select*

From student

Where s_id in(select s_id from score where c_id is null or c_id=’’)

12、查询至少有一门课与学号为"01"的同学所学相同的同学的信息

Select*

From student as s

Inner join score as sc on s.s_id-sc.s_id

Where sc.c_id in (select c_id from score where s_id=’01’)

13、查询和"01"号的同学学习的课程完全相同的其他同学的信息

Select*

From student as s

Inner join score as sc on s.s_id-sc.s_id

Where sc.c_id = (select c_id from score where s_id=’01’)

14、查询没学过"张三"老师讲授的任一门课程的学生姓名

Select s_name as 学生姓名

From student

Where s_id not in(select s_id from score where c_id inselect c_id from course where t_id inselect t_id from teacher where t_name=’张三’)

 

15、查询两门及其以上不及格课程的同学的学号,姓名及其平均成绩

Select s.s_id as 学生学号,s.s_name as 学生姓名,avgsc.s_scoreas 平均成绩

From student as s

Inner join score as sc on s.s_id=sc.s_id

Where s.s_id in(select s_id from score where s_score<60 group by s_id having count(s_id)>2)

Group by s.s_id,s.s_name

 

以上是关于周测代码的主要内容,如果未能解决你的问题,请参考以下文章

数据结构与算法(周测3)

周测一总结

周测3.1

周测总结

java面向对象周测带答案

数学周测3讲解