0

我明天有一个数据库测试,希望有人可以为我确认这个答案。假设我有一个这样的模式:

branch (branch_name, branch_city, assets)
customer (customer_name, customer_street, customer_city)
account (account_number, branch_name, balance)
loan (loan_number, branch_name, amount)
depositor (customer_name, account_number)
borrower (customer_name, loan_number)

我很好奇的问题是:“找出所有贷款超过 5000 英镑但没有账户余额超过 500 英镑的客户的姓名。”

原始代码:

π customer_name
  (σ amount > 5,000 ^ balance < 500 
    (borrower ⋈ loan ⋈ depositor ⋈ account))

编辑:看过 Erwin Smout 的建议后,我将代码修改为以下内容:

π customer_name
  (σ amount > 5,000 (borrower ⋈ loan))
-
π customer_name
  (σ balance < 500 (depositor ⋈ account))   

那是对的吗?

4

2 回答 2

3

不,这是不正确的。短语“但 [没有] 帐户 ...”表示您应该在某处使用关系差异运算符。

于 2012-11-19T21:50:07.143 回答
0

我只会回答我自己的问题,因为我现在知道它是正确的。感谢所有帮助过的人:

π customer_name (σ amount > 5,000 (borrower ⋈ loan))    
-
π customer_name (σ balance < 500 (depositor ⋈ account))   
于 2012-11-20T17:51:39.400 回答