如何为以下查询编写关系代数表达式?

时间:2012-04-16 16:46:55

标签: sql tsql relational-algebra

如何为以下查询编写关系代数表达式?

select Customer_ID
from tbl_Reservation
where Customer_ID not in (select Customer_ID from tbl_Bill)

1 个答案:

答案 0 :(得分:2)

这样的事情:

excludedCustomers = π(Customer_ID)(tbl_Bill)
customerReservations= π(Customer_ID)(tbl_Reservation)
result = customerReservations- excludedCustomers

您只需要获取要排除的客户的投影(全部来自tbl_Bill),对tbl_Reservation执行相同的操作,并从两个投影中减去这些是您的答案。