-1
  1. 从 branch = 'Pennywell' 的交易中选择 account_no、amount、customer

  2. 选择 c.customer_name, c.cust_street, c.cust_city, b.branch_name, b.branch_city, a.account_no, a.balance from customer c, transactions t, accounts a, branch b where t.customer = c.customer_name and a .account_no = t.account_no 和 b.branch_name = a.branch_name

  3. select customer_name, cust_city from customer where customer_name not in(从交易中选择客户)

4

1 回答 1

0

第一个只是 Pennywell 上的选择,然后是 account_no、amount、customer 上的投影:

\pi_{account_no, amount, customer} (\sigma_branch = 'Pennywell'(transactions))

第二个遵循相同的原则:

  1. 列出所有表格:

客户、交易、账户、分支机构

  1. 使用 \rho 重命名每个:

\rho_c(客户),\rho_t(交易),\rho_a(账户),\rho_b(分支机构)

  1. 计算笛卡尔积

\rho_c(客户)x \rho_t(交易)x \rho_a(账户)x \rho_b(分支)

  1. 对第 3 步的结果执行选择(“where”),用连词替换和,或者用析取而不是否定:

\sigma_{t.customer = c.customer_name /\ a.account_no = t.account_no /\ b.branch_name = a.branch_name}(\rho_c(客户) x \rho_t(交易) x \rho_a(账户) x \rho_b (分支))

  1. 最后执行投影:

\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_{客户名称}(交易)

是我们想要忽略的所有客户和

\pi_{客户名称}(客户)

都是客户。因此,

\pi_{customer_name}(客户) - \pi_{customer_name}(交易)

都是我们想要保留的。最后我们需要找到他们的城市(为了简单起见,我使用了连接运算符 |x|):

\pi_{customer_name, cust_city}((\pi_{customer_name}(customer) - \pi_{customer_name}(transactions)) |x| customer)

于 2013-02-15T22:29:46.947 回答