我明天有一个数据库测试,希望有人可以为我确认这个答案。假设我有一个这样的模式:
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))
那是对的吗?