练习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

posted @ 2019-04-28 21:48  熊猫橙子  阅读(2826)  评论(0)    收藏  举报