練習5--查詢學過編號為"01"並且也學過編號為"02"的課程的同學的信息|查詢沒有學全所有課程的同學的信息


--查詢學過編號為"01"並且也學過編號為"02"的課程的同學的信息

select
    *
from
    student
where
    s_id in (
        select t1.s_id
    from
        score t1,
        score t2
    where
        t1.s_id = t2.s_id
        and t1.c_id = '01'
        and t2.c_id = '02');
select
    a.*
from
    student a,
    score b,
    score c
where
    a.s_id = b.s_id
    and a.s_id = c.s_id
    and b.c_id = '01'
    and c.c_id = '02';

-- 查詢沒有學全所有課程的同學的信息 

select
    a.*
from
    student a,
    score b
where
    a.s_id = b.s_id
group by
    b.s_id
having
    count(b.c_id) != '3';
select
    s.*
from
    student s
where
    s.s_id in(
    select
        s_id
    from
        score
    where
        s_id not in(
        select
            a.s_id
        from
            score a
        join score b on
            a.s_id = b.s_id
            and b.c_id = '02'
        join score c on
            a.s_id = c.s_id
            and c.c_id = '03'
        where
            a.c_id = '01'))

 

-- 2019/4/21


免責聲明!

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



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