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

posted @ 2019-04-21 23:08  熊猫橙子  阅读(6855)  评论(0)    收藏  举报