我明天有数据库测试,希望有人可以为我确认这个答案。说我有一个这样的架构:
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))
这是对的吗?
答案 0 :(得分:3)
不,这不对。短语“但[没有]帐户......”表示您应该在某处使用关系差异运算符。
答案 1 :(得分:0)
我只是回答我自己的问题,因为我现在知道这是正确的。感谢所有帮助过的人:
π customer_name (σ amount > 5,000 (borrower ⋈ loan))
-
π customer_name (σ balance < 500 (depositor ⋈ account))