2018-12-28

   本周总结:了解了python的基础知识,对其有一个大致的了解;复习SQL知识点,并着手练习SQL50题(ps:本周后续几天有事无法学习,下周最低每天学习3h补回进度)。
   下周计划:必须完成SQL50题练习,尽可能学习一些excel透视分析的知识。
   目前进度如下:
    1、查询" 01 "课程比" 02 "课程成绩高的学生的信息及课程分数
    SELECT aa.*, bb.s_score AS 01_score,cc.s_score AS 02_score
    FROM student AS aa
    LEFT JOIN score AS bb ON aa.s_id=bb.s_id AND bb.c_id='01'
    LEFT JOIN score AS cc ON bb.s_id=cc.s_id AND cc.c_id='02'
    WHERE cc.s_score>bb.s_score;

   1.1 查询同时存在" 01 "课程和" 02 "课程的情况
   SELECT aa.*, bb.s_score as 01_score,cc.s_score as 02_score
   FROM student AS aa
   INNER JOIN score AS bb ON aa.s_id=bb.s_id AND bb.c_id='01'
   INNER JOIN score AS cc ON bb.s_id=cc.s_id AND cc.c_id='02';

  1.2查询存在" 01 "课程但可能不存在" 02 "课程的情况(不存在时显示为 null )
 SELECT aa.*, bb.s_score as 01_score,cc.s_score as 02_score
 FROM student AS aa
 INNER JOIN score AS bb ON aa.s_id=bb.s_id AND bb.c_id='01'
 LEFT JOIN score AS cc ON bb.s_id=cc.s_id AND cc.c_id='02';

 1.3 查询不存在" 01 "课程但存在" 02 "课程的情况
 SELECT aa.*, cc.s_score as 02_score,bb.s_score as 01_score
 FROM student AS aa
 INNER JOIN score AS cc ON aa.s_id=cc.s_id AND cc.c_id='02'
 LEFT JOIN score AS bb ON cc.s_id=bb.s_id AND bb.c_id='01'
 WHERE bb.s_score IS NULL;

 2. 查询平均成绩大于等于 60 分的同学的学生编号和学生姓名和平均成绩
 SELECT student.s_id, student.s_name, 
 CAST(AVG(score.s_score) AS decimal(10,2)) AS AVG_score
 FROM student INNER JOIN score ON student.s_id=score.s_id
 GROUP BY student.s_id
 HAVING AVG(score.s_score)>=60;
 疑问:CAST(AVG(score.s_score) AS decimal(10,2))和AVG(CAST(score.s_score AS decimal(10,2)))为啥结果不一致,第 
一个保留2位小数,第二个不是2位小数。

 3. 查询在 score 表存在成绩的学生信息
  SELECT *
  FROM student
  WHERE student.s_id IN
      (SELECT DISTINCT s_id FROM score );

 4.查询所有同学的学生编号、学生姓名、选课总数、所有课程的 
 总成绩(没成绩的显示为 null )
  SELECT student.s_id,student.s_name, count(score.c_id) AS 
  num_course, SUM(score.s_score) AS total_score
  FROM student LEFT JOIN score ON student.s_id=score.s_id
  GROUP BY score.s_id;

 4.1 查有成绩的学生信息
 SELECT student.s_id,student.s_name, count(score.c_id) AS 
 num_course, SUM(score.s_score) AS total_score
 FROM student INNER JOIN score ON student.s_id=score.s_id
 GROUP BY score.s_id;

 5.查询「李」姓老师的数量
 SELECT count(*) AS 李姓老师数量 FROM teacher
 WHERE t_name LIKE'李%';

你可能感兴趣的:(2018-12-28)