如何检查关系数据库中的多个条目?

时间:2014-02-27 01:14:36

标签: relational-database relational-algebra

例如,编写一个查询以向学生展示多个班级。

myQuery :=
    (project studID (select (count(studID) > 1)(schoolRoster)));

假设schoolRoster包含为每个学生注册的学生的studID和classID(如果该学生注册了多个班级,那么它将具有重复的studID)。

我需要的是它只显示那些有多个班级的学生的学生ID,但我的计数数据结构不起作用。你能帮我知道我会做什么吗?

1 个答案:

答案 0 :(得分:0)

所以,我在一位同事的帮助下想出了这一点。我希望它会帮助别人。为此,您需要复制查询并操作数据,如下面的代码所示。

myQuery :=
    project studID, classID (schoolRoster);
myQueryCopy(studID2, classID2) :=
    myQuery;
checkMoreThanOne(ID) :=
    project studID(select studID = studID2 and classID <> classID2(myQuery product myQueryCopy));
% At this point you could be done, but if you need additional information from the original table, you can get it with one more line of code (myQueryFinal)
myQueryFinal :=
    project studID, studAge (select ID = studID (checkMoreThanOne njoin schoolRoster));