我的关系代数可能有点生疏,但我认为
dept_name_G_{max(salary)}(
σ_{ddept_name = idept_name}(
ρ_{dept_name/ddept_name}(department) ⨯
ρ_{dept_name/idept_name}(instructor)
)
)
是你所寻求的。
请记住,所有投影都只是对集合的操作。你要做的第一件事
连接department 和instructor 的信息是把信息放在一起。
所以你想加入department和instructor,基本上是一个叉积(⨯):
department = {(depA, 100$), (depB, 200$)}
instructor = {(will, depA, 10$), (bob, depB, 20$), (will, depB, 9$)}
department ⨯ instructor = {
(depA, 100$, will, depA, 10$),
(depA, 100$, bob, depB, 20$),
...,
(depB, 200$, will, depA, 10$),
...
}
所以你现在想要的是过滤教师的dept_name 等于
部门的dept_name。但是你也注意到你现在有一个命名冲突,
即dept_name 列出现两次。
因为你不能简单地做σ_{dept_name = dept_name}(department ⨯ instructor),你需要重命名为
dept_name 字段中的至少一个。为了清楚起见,我将两者都重命名了。
所以你现在拥有的是
σ_{ddept_name = idept_name}(
ρ_{dept_name/ddept_name}(department) ⨯
ρ_{dept_name/idept_name}(instructor)
)
给你:
{
(depA, 100$, will, depA, 10$),
(depB, 200$, bob, depB, 20$),
(depB, 200$, will, depB, 9$)
}
整个过程是一个natural join,可以简写成:
department ⋈ instructor
现在最后一步是预测每个部门的最高工资。一个简单的投影不能做到这一点
但aggregation operator 可以:
{dept_name}_G_{max(salary)}(department ⋈ instructor)
结果
{
(depA, 10$),
(depB, 20$)
}