Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 查找修读完全相同课程的学生列表_Mysql_Sql - Fatal编程技术网

Mysql 查找修读完全相同课程的学生列表

Mysql 查找修读完全相同课程的学生列表,mysql,sql,Mysql,Sql,我见过很多这样的问题,但是在回顾了这里的其他问题之后,我仍然不明白该怎么办 Select s1.email From student s, student s1 where s1.sname <> 'Alice' and not exists (select 1 from enrol e, course c, enrol e1 where s.sname = 'Alice' and s.s

我见过很多这样的问题,但是在回顾了这里的其他问题之后,我仍然不明白该怎么办

Select s1.email
From student s, student s1
where s1.sname <> 'Alice'
and not exists (select 1
                from enrol e, course c, enrol e1
                where s.sname = 'Alice'
                and s.sid = e.sid
                and s1.sid = e1.sid         
                and e1.code <> e.code );
请参阅:

这是我的示例数据库,添加了一些伪值,以便测试此SQL查询

我想做的是找出那些修过与这个叫爱丽丝的学生完全相同的课程的学生名单

我见过的许多SQL查询都不存在。所以我试图实现它,但失败了。我应该b@hotmail而不是b@hotmail和c@hotmail. 因为只有鲍勃和爱丽丝上了完全一样的课


提前谢谢

尝试以下查询

SELECT *
FROM
  (
    SELECT s.sid,s.email,GROUP_CONCAT(e.code ORDER BY code) course_list
    FROM student s
    JOIN enrol e ON e.sid=s.sid
    WHERE s.sname<>'Alice'
    GROUP BY s.sid,s.email
  ) q
WHERE course_list=(
        SELECT GROUP_CONCAT(e.code ORDER BY code) course_list
        FROM enrol e
        JOIN student s ON e.sid=s.sid
        WHERE s.sname='Alice'
      )

请尝试以下查询

SELECT *
FROM
  (
    SELECT s.sid,s.email,GROUP_CONCAT(e.code ORDER BY code) course_list
    FROM student s
    JOIN enrol e ON e.sid=s.sid
    WHERE s.sname<>'Alice'
    GROUP BY s.sid,s.email
  ) q
WHERE course_list=(
        SELECT GROUP_CONCAT(e.code ORDER BY code) course_list
        FROM enrol e
        JOIN student s ON e.sid=s.sid
        WHERE s.sname='Alice'
      )
请尝试此查询

select email 
from student where sid in 
(select distinct sid from enrol where code in 
 (select distinct code from enrol where sid in 
  (select sid from student where sname = 'Alice') --In case you have more than one Alice students it still get all classmate of all Alice
 )
)
and sname <> 'Alice'
请尝试此查询

select email 
from student where sid in 
(select distinct sid from enrol where code in 
 (select distinct code from enrol where sid in 
  (select sid from student where sname = 'Alice') --In case you have more than one Alice students it still get all classmate of all Alice
 )
)
and sname <> 'Alice'

如果Alice注册了多个课程,你想让其他学生注册这些课程,对吗?是的,我想。只显示与Alice注册完全相同的课程。您是想熟悉不存在的课程,还是只想要结果?如果您想要的只是结果,请尝试此查询从学生s中选择不同的s.email,注册e,课程c,其中s.sname'Alice'和e.sid=s.sid和e.code从学生s1中选择c1.code,注册e1,课程c1,其中s1.sname='Alice'和e1.sid=s1.sid和e1.code=c1.code;如果Alice注册了多个课程,你想让其他学生注册这些课程,对吗?是的,我想。只显示与Alice注册完全相同的课程。您是想熟悉不存在的课程,还是只想要结果?如果您想要的只是结果,请尝试此查询从学生s中选择不同的s.email,注册e,课程c,其中s.sname'Alice'和e.sid=s.sid和e.code从学生s1中选择c1.code,注册e1,课程c1,其中s1.sname='Alice'和e1.sid=s1.sid和e1.code=c1.code;