从branch ='Pennywell'的交易中选择account_no,金额,客户
选择c.customer_name,c.cust_street,c.cust_city,b.branch_name,b.branch_city,a.account_no,来自客户c的a.balance,交易t,账户a,分支b 其中t.customer = c.customer_name和a.account_no = t.account_no和b.branch_name = a.branch_name
从customer_name不在的客户中选择customer_name,cust_city(从交易中选择客户)
答案 0 :(得分:0)
第一个是Pennywell的选择,然后是account_no,amount,customer:
上的投影\pi_{account_no, amount, customer} (\sigma_branch = 'Pennywell'(transactions))
第二个遵循相同的原则:
客户,交易,账户,分支机构
\ rho_c(客户),\ rho_t(交易),\ rho_a(账户), \ rho_b(分支)
\ rho_c(客户)x \ rho_t(交易)x \ rho_a(账户)x \ rho_b(分支)
\ sigma_ {t.customer = c.customer_name / \ a.account_no = t.account_no / \ b.branch_name = a.branch_name}(\ rho_c(customer)x \ rho_t(transactions)x \ rho_a(accounts) x \ rho_b(分支))
\ pi_ {c.customer_name,c.cust_street,c.cust_city,b.branch_name,b.branch_city,a.account_no,a.balance}(\ sigma_ {t.customer = c.customer_name / \ a.account_no = t.account_no / \ b.branch_name = a.branch_name}(\ rho_c(customer)x \ rho_t(transactions)x \ rho_a(accounts)x \ rho_b(branch)))
最后一个查询有点棘手,需要更多思考。
\ pi_ {CUSTOMER_NAME}(事务)
是我们想要忽略的所有客户
\ pi_ {CUSTOMER_NAME}(客户)
是所有客户。因此,
\ pi_ {customer_name}(客户) - \ pi_ {customer_name}(交易)
是我们想要保留的所有内容。最后,我们需要找到他们的城市(为了简单起见,我使用的是连接运算符| x |):
\ pi_ {customer_name,cust_city}((\ pi_ {customer_name}(客户) - \ pi_ {customer_name}(交易))| x | customer)