讲课刷的题,做个笔记
1、 查询lesson表中所有考试课课程,显示列名为[课程名称]、[课程类型]
2、 查询lesson表中所有学分大于等于3的课程,显示列名为[课程名称]、[课程学分]
3、 查询user_info表,班级ID不为1004的所有学生数据,显示account、student_name、class_id
4、 查询lesson表中所有学分在[2,3]区间的课程,显示lesson_name , score
5、 查询lesson表中所有学分为1、3的课程,显示lesson_name , score
6、 查询user_info表,班级ID为1002或1003,且性别为女的所有学生数据,显示student_name、class_id,并且按班级ID排序
7、 查询user_info表,查询所有姓何的学生,显示account,student_name
8、 查询user_info表,查询所有名字中带方的学生,显示account,student_name
9、 查询user_info表,查询所有姓陈且名字只有两个字的学生,显示account,student_name
/*
1、 查询lesson表中所有考试课课程,显示列名为[课程名称]、[课程类型]
*/
select lesson_name as "课程名称" , lesson_type as "课程类型" from lesson;
/*
2、 查询lesson表中所有学分大于等于3的课程,显示列名为[课程名称]、[课程学分]
*/
select lesson_name as "课程名称" , score as "课程学分" from lesson where score >= 3;
/*
3、 查询user_info表,班级ID不为1004的所有学生数据,显示account、student_name、class_id
*/
select account , student_name , class_id from user_info where class_id != 1004;
select account , student_name , class_id from user_info where class_id <> 1004;
/*
4、 查询lesson表中所有学分在[2,3]区间的课程,显示lesson_name , score
*/
select lesson_name , score from lesson where score between 2 and 3;
/*
5、 查询lesson表中所有学分为1、3的课程,显示lesson_name , score
*/
select lesson_name , score from lesson where score in (1,3);
select lesson_name , score from lesson where score = 1 or score = 3;
/*
6、 查询user_info表,班级ID为1002或1003,且性别为女的所有学生数据,显示student_name、class_id,并且按班级ID排序
*/
select student_name , class_id from user_info where sex = '女' and (class_id =1002 or class_id =1003) order by class_id ;
select student_name , class_id from user_info where sex = '女' and class_id in (1002,1003) order by class_id ;
/*
7、 查询user_info表,查询所有姓何的学生,显示account,student_name
*/
select account , student_name from user_info where student_name like "何%" ;
/*
8、 查询user_info表,查询所有名字中带方的学生,显示account,student_name
*/
select account , student_name from user_info where student_name like "%方%" ;
/*
9、 查询user_info表,查询所有姓陈且名字只有两个字的学生,显示account,student_name
*/
select account , student_name from user_info where student_name like "陈_" ;
* 显示t_class_msg 表 班级全称 为 [班级名称] 例如:2017级信息管理1班
* 查询所有高等数学(一)的课程成绩加10分显示
* 给id为208的同学,生日加一天显示,并显示当前时间为now_time 字段
* 查询user_info 女生的数量
* 查询lesson_score 计算高等数学(一)的平均分数
* 查询lesson_score 计算学号为201703024001的各科总成绩
/*
* 显示t_class_msg 表 班级全称 为 [班级名称] 例如:2017级信息管理1班
*/
select concat(grade, '级', class_name , num , '班' ) as '班级名称' from t_class_msg;
/*
* 查询所有高等数学(一)的课程成绩加10分显示
*/
select id, score+10 as score from lesson_score where lesson_name ='高等数学(一)';
/*
* 给id为208的同学,生日加一天显示,并显示当前时间为now_time 字段
*/
select date_add(birthday, interval 1 day) as birthday ,now() as now_time from user_info where id = 208;
/*
* 查询user_info 女生的数量
*/
select count(1) from user_info where sex = '女';
/*
* 查询lesson_score 计算高等数学(一)的平均分数
*/
select avg(score) from lesson_score where lesson_name = '高等数学(一)' ;
/*
* 查询lesson_score 计算学号为201703024001的各科总成绩
*/
select sum(score) from lesson_score where stu_num = '201703024001';
* 查询lesson 表中 考试课和考查课各有几门
* 查询lesson 表中 统计每种学分的课程数量,只显示大于等于3的课程信息
* lesson_score 表中 课程成绩数量小于3的学生 显示 学号 和课程数量
* 查询user_info表中 id 为 245 的同学的成绩信息 显示学生姓名、课程名称、课程分数
* 查询课程成绩大于80分的同学,显示student_name和lesson_name和score
* 显示lesson表中所有课程的平均分(lesson_name、score)
/*
* 1、查询lesson 表中 考试课和考查课各有几门
*/
select stu_num '学号' , count(*) '课程数量' from lesson_score group by stu_num having count(*) <3
/*
* 2、查询lesson 表中 统计每种学分的课程数量,只显示大于等于3的课程信息
*/
select lesson_type, score, count(*) as 'num' from lesson where score >= 3 group by score
/*
* 3、lesson_score 表中 课程成绩数量小于3的学生 显示 学号 和课程数量
*/
select lesson_type , count(*) as 'num' from lesson group by lesson_type
/*
* 1、 查询user_info表中 id 为 245 的同学的成绩信息 显示学生姓名、课程名称、课程分数
*/
select ui.student_name '学生姓名', ls.lesson_name '课程名称', ls.score '课程分数'
from user_info ui
inner join lesson_score ls on ui.id= ls.student_id
where ui.id =245
/*
* 查询课程成绩大于80分的同学,显示student_name和lesson_name和score
*/
select ui.student_name , ls.lesson_name , ls.score
from user_info ui left outer join lesson_score ls on ui.id=ls.student_id
where ls.score > 80;
/*
* 显示lesson表中所有课程的平均分(lesson_name、score)
*/
select lesson.lesson_name , avg(ls.score) as score
from lesson left outer join lesson_score ls on ls.lesson_id =lesson.id
group by lesson.id
order by score desc ;