練習1--查詢"01"課程比"02"課程成績高的學生的信息及課程分數


查詢"01"課程比"02"課程成績高的學生的信息及課程分數 

-- 解法一:

    select
        s1.*,
        s2.01_score,
        s2.02_score
    from
        student s1,
        (
            select t1.s_id as s_id,
            t1.s_score as 01_score,
            t2.s_score as 02_score
        from
            score t1,
            score t2
        where
            t1.s_id = t2.s_id
            and t1.c_id = '01'
            and t2.c_id = '02'
            and t1.s_score > t2.s_score ) s2
    where
        s1.s_id = s2.s_id;

 

--參考解法

    select
        a.* ,
        b.s_score as 01 _score,
        c.s_score as 02 _score
    from
        student a
    join score b on
        a.s_id = b.s_id
        and b.c_id = '01'
    left join score c on
        a.s_id = c.s_id
        and c.c_id = '02'
        or c.c_id = null
    where
        b.s_score>c.s_score;

-- 2019/04/15


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM