[考试]周测(2017/10/27)

来源:互联网 发布:做视频短片的软件 编辑:程序博客网 时间:2024/06/06 03:29

student表:
这里写图片描述

score表:
这里写图片描述

题目:

2.查询student表的所有记录

SELECT * FROM student;

3.查询student表的第二条到第四条记录

SELECT * FROM student LIMIT 1,3;

4.从student表查询所有学生的学号(id)、姓名(name)和院系(department)的信息

SELECT id,name,department FROM student;

5.从student表中查询计算机系和英语系的学生的信息(用IN关键字)

SELECT * FROM student WHERE department IN ('计算机系','英语系');

6.从student表中查询年龄18~22岁的学生的信息(用 BETWEEN AND)

SELECT * FROM student WHERE 2017-birth BETWEEN 22 AND 26;

7.从student表中查询每个院系有多少人

SELECT department,count(*)AS '人数' FROM student GROUP BY department;

8、从score表中查询每个科目的最高分

SELECT c_name,MAX(grade)FROM score GROUP BY c_name;

9、查询李四的考试科目(c_name)和考试成绩(grade)

SELECT c_name,grade FROM student LEFT JOIN score ON student.id=score.stu_id WHERE student.name='李四';

10、用连接的方式查询所有学生的信息和考试信息

SELECT * FROM student LEFT JOIN score ON student.id=score.stu_id;

11、计算每个学生的总成绩

SELECT s.stu_id,SUM(grade) FROM score s GROUP BY s.stu_id;

12、计算每个考试科目的平均成绩

SELECT s.c_name,AVG(grade) FROM score s GROUP BY s.c_name;

13、查询计算机成绩低于95的学生信息

SELECT * FROM score s WHERE grade<95;

14、查询同时参加计算机和英语考试的学生的信息

-- 第一种 select st.* from student st,score s1,score s2 where st.id = s1.stu_id and st.id = s2.stu_id and s1.c_name = '计算机' and s2.c_name = '英语'-- 第二种:select st.* from student st INNER JOIN score s1 on s1.stu_id = st.id and s1.c_name = '英语'inner JOIN score s2 on s2.stu_id = st.id AND s2.c_name = '计算机';-- 第三种:select st.* from student st INNER JOIN score s1 on s1.stu_id = st.id inner JOIN score s2 on s2.stu_id = st.id where s1.c_name = '英语' and s2.c_name = '计算机'

15、将计算机考试成绩按从高到低进行排序

SELECT * FROM score WHERE score.c_name='计算机' AND grade<95 ORDER BY grade DESC 

16、从student表和score表中查询出学生的学号,然后合并查询结果

SELECT id FROM studentUNIONSELECT stu_id FROM score

17、查询姓张或者姓王的同学的姓名、院系和考试科目及成绩

SELECT st.name,st.department,sc.c_nameFROM score scLEFT JOIN student st ON st.id=sc.stu_idWHERE (st.name LIKE '王%' )OR (st.name LIKE '张%' )

18、查询都是湖南的学生的姓名、年龄、院系和考试科目及成绩

SELECT *FROM score scLEFT JOIN student st ON st.id=sc.stu_idWHERE st.address LIKE '湖南%' 
原创粉丝点击