根据作业文件中的表和数据,创建表并完成以下查询:
    1、查询”李”姓老师的数量
    2、查询1990年出生的学生名单
    3、查询男生、女生人数
    4、查询学生的总成绩、平均成绩并进行排名
    5、查询每门课程被选修的学生数
    6、查询学过编号为”01”并且也学过编号为”02”的课程的同学的信息
    7、查询平均成绩大于等于85的所有学生的学号、姓名和平均成绩
    8、检索至少选修两门课程的学生学号
    9、统计各科成绩各分数段[100-85],[85-70],[70-60],[0-60]的人数

    1. # 1. 查询"李"姓老师的数量
    2. SELECT count(1) FROM T WHERE t_name LIKE '李%';
    3. # 2. 查询1990年出生的学生名单
    4. SELECT * FROM S WHERE YEAR(s_birth) = 1990;
    5. # 3. 查询男生、女生人数
    6. SELECT s_gend, COUNT(1) FROM S GROUP BY s_gend;
    7. # 4. 查询学生的总成绩、平均成绩并进行排名
    8. SELECT a.s_id,
    9. @i: = @i + 1 as i,
    10. @k: = (case when @score = a.sum_score then @k else @i end) as rank1,
    11. @score:= a.sum_score as score
    12. from (select s_id, s_name
    13. ,SUM(s_score) as sum_score
    14. from score
    15. GROUP BY s_id
    16. ORDER BY sum_score DESC) a
    17. ,
    18. (select @k: = 0, @i: = 0, @score: = 0) s;
    19. # 5. 查询每门课程被选修的学生数
    20. SELECT C.c_name, COUNT(S.s_id) FROM S join Score on S.s_id = Score.s_id join C on C.id = Score.c_id GROUP BY C.id;
    21. # 6. 查询学过编号为"01"并且也学过编号为"02"的课程的同学的信息
    22. select a.* from
    23. student a, score b, score c
    24. where a.s_id = b.s_id and a.s_id = c.s_id and b.c_id = '01' and c.c_id = '02';
    25. # 7. 查询平均成绩大于等于85的所有学生的学号、姓名和平均成绩
    26. SELECT a.s_id
    27. , b.s_name
    28. , ROUND(AVG(s_score), 2) as `avg_score`
    29. from score a
    30. left join student b
    31. on a.s_id = b.s_id
    32. GROUP BY s_id
    33. Having avg_score > 85;
    34. # 8. 检索至少选修两门课程的学生学号
    35. select s_id, count(*) as sel from score GROUP BY s_id HAVING sel >= 2;
    36. # 9. 统计各科成绩各分数段[100-85],[85-70],[70-60],[0-60]的人数
    37. select c_id
    38. , sum(case when s_score > 85 and s_score <= 100 then 1 else 0 end) as `85-100`,
    39. , sum(case when s_score > 70 and s_score <= 85 then 1 else 0 end) as `70-85`,
    40. , sum(case when s_score > 60 and s_score <= 70 then 1 else 0 end) as `60-70`,
    41. , sum(case when s_score > 0 and s_score <= 60 then 1 else 0 end) as `0-60`,
    42. from score
    43. left join C
    44. on C.id = score.c_id
    45. group by c_id;