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