练习6--查询至少有一门课与学号为"01"的同学所学相同的同学的信息| 查询和"01"号的同学学习的课程完全相同的其他同学的信息


-- 查询至少有一门课与学号为"01"的同学所学相同的同学的信息 

** group_concat函数将学生所学课程转化为字符串,比较字符串

select
    *
from
    student
where
    s_id in(
    select
        distinct b.s_id
    from
        score b
    where
        b.c_id in (
            select c_id
        from
            score
        where
            s_id = '01'))

-- 查询和"01"号的同学学习的课程完全相同的其他同学的信息

select
    *
from
    student
where
    s_id in (
    select
        s_id
    from
        score t1
    group by
        s_id
    having
        group_concat(c_id) = (
            select group_concat(c_id) as str2
        from
            score
        where
            s_id = '01')
        and s_id != '01');

** A是B的子集,且AB元素个数相同,则AB相等

select
    a.*
from
    student a
where
    a.s_id in(
    select
        distinct s_id
    from
        score
    where
        s_id != '01'
        and c_id in(
            select c_id
        from
            score
        where
            s_id = '01')
    group by
        s_id
    having
        count(1)=(
            select count(1)
        from
            score
        where
            s_id = '01'));

 --2019/04/22 and 04/23


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM