0
点赞
收藏
分享

微信扫一扫

详解索引及优化

东言肆语 2024-04-02 阅读 6
数据库

相关表数据: 

  1. Score_info表

     2、Student_info表

    3、Course_info表 

 4、Teacher_info 表

题目及思路解析:

 多表连接

题目:查询所有课程成绩在70分以上的学生的姓名、课程名称和分数,按分数升序排列

     第一种:

select 
    sc.stu_id,
    stu_name,
    course_name,
    score
from score_info sc
left join student_info st on st.stu_id = sc.stu_id
left join course_info ci on sc.course_id = ci.course_id
where score>70;

   第二种:

代码:
select
    s.stu_id,
    s.stu_name,
    c.course_name,
    s2.score
from student_info s
join (
    select
        stu_id,
        sum(if(score >= 70,0,1)) flage
    from score_info
    group by stu_id
    having flage =0
    ) t1
on s.stu_id = t1.stu_id
left join score_info s2 on s.stu_id = s2.stu_id
left join course_info c on s2.course_id = c.course_id;
 思路解析:

 说明补充:

知识补充:

举报

相关推荐

0 条评论