【发布时间】:2014-09-01 14:48:23
【问题描述】:
select r.index, sum(c.points)
from records r join exams e2 on r.index = e2.index
join courses c on c.id_course = e2.id_course
where not exists ( select *
from required_courses rs
where rs.id_studie = r.id_studie
and not exists (select *
from exams e
where e.id_course = rs.id_course
and r.index = e.index
and score>5))
and score>5
group by index;
我有这个问题。我知道它的作用,但不知道怎么做。
我有 16 个表的相对较大的数据库,但在这个查询中只使用了 4 个。
使用的表是:
- 记录(学生)[索引(pr.key),name,surname,...,id_studie(1)(for.key)]
- 考试 [index(of students) (p.k.), id_course(p.k.),..., score(2), application_status]
- 课程 [id_course(p.k.), ..., 积分]
- REQUIRED_COURSES [id_studie (f.k.), id_course(f.k), ...]
(1) 我不知道更好的英文单词。在某些教职员工中,有信息学、数学、物理等课程。信息学是一门研究。 (2) 分数从 5 到 10。10 是最好的。至少需要 6 个才能通过。
查询: - 查找所有通过了 studie thay studie 所需考试的所有学生。打印索引和点数。
我的问题:可以用简单的话解释一下这是如何工作的吗?
我不明白不存在和不存在的部分。
对不起,我的英语不好。
【问题讨论】:
-
我认为 Joe Celko 的这篇文章可能会对您有所帮助:Divided We Stand: The SQL of Relational Division
-
这真的很有帮助。非常感谢你。我不知道这叫除法。