練習9--檢索"01"課程分數小於60,按分數降序排列的學生信息 | 按平均成績從高到低顯示所有學生的所有課程的成績以及平均成績


-- 檢索"01"課程分數小於60,按分數降序排列的學生信息

select
    t2.*
from
    score t1,
    student t2
where
    t2.s_id = t1.s_id
    and t1.s_score < '60'
    and t1.c_id = '01'
order by
    t1.s_score;

 

-- 按平均成績從高到低顯示所有學生的所有課程的成績以及平均成績

select
    a.*,
    b.c_id,
    b.s_score
from
    student a,
    score b
where
    a.s_id = b.s_id
    and b.c_id = '01'
    and b.s_score<60
order by
    b.s_score desc;
select
    a.s_id,
    (
        select s_score
    from
        score
    where
        s_id = a.s_id
        and c_id = '01') as 語文,
    (
        select s_score
    from
        score
    where
        s_id = a.s_id
        and c_id = '02') as 數學,
    (
        select s_score
    from
        score
    where
        s_id = a.s_id
        and c_id = '03') as 英語,
    round(avg(a.s_score), 1)
from
    score a
group by
    a.s_id
order by
    avg(a.s_score) desc;

 

--2019/04/28


免責聲明!

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



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