代码之家  ›  专栏  ›  技术社区  ›  user4591951

关系代数与混淆一个复杂的例子

  •  2
  • user4591951  · 技术社区  · 10 年前

    我们有三种关系:

    Students(sid, sname)
    Courses(cid, cname, dept)
    take(sid, cid, grade)
    

    We want to find student numbers of students whose these students take all courses that present in 'CS' department .

    为什么(第4行)是这个问题的答案?

    任何人都可以说不同于(第1行)到(第3行)。我在DB的Solved Ex中读到了这篇文章。

    enter image description here

    1 回复  |  直到 10 年前
        1
  •  1
  •   Andomar    10 年前

    第四行的另一种表达方式是:

    all students
    except
    (
        all combinations of students and CS courses
        except
        all taken courses
    )
    

    括号之间的集合包含所有未参加的学生+CS课程组合。从所有学生中减去这个,你就得到了参加所有CS考试的学生。