branch = 'Pennywell' であるトランザクションから、account_no、amount、customer を選択します
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 を選択します。ここで、t.customer = c.customer_name および a .account_no = t.account_no および b.branch_name = a.branch_name
select customer_name, cust_city from customer where customer_name not in (トランザクションから顧客を選択)
1 に答える
1 つ目は、Pennywell の選択に続いて、account_no、amount、customer のプロジェクションです。
\pi_{account_no, amount, customer} (\sigma_branch = 'Pennywell'(transactions))
2 番目のものは同じ原則に従います。
- すべてのテーブルを一覧表示します。
顧客、取引、口座、支店
- \rho を使用してそれぞれの名前を変更します。
\rho_c(顧客)、\rho_t(取引)、\rho_a(口座)、\rho_b(支店)
- デカルト積を計算する
\rho_c(顧客) x \rho_t(トランザクション) x \rho_a(口座) x \rho_b(支店)
- ステップ 3 の結果に対して、and を接続詞に置き換えるか、否定ではなく選言によって選択 ("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 (ブランチ))
- 最後に投影を実行します。
\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(顧客) x \rho_t(トランザクション) x \rho_a(アカウント) x \rho_b(ブランチ)))
最後のクエリはもう少しトリッキーで、もう少し考える必要があります。
\pi_{顧客名}(取引)
無視したいすべての顧客であり、
\pi_{顧客名}(顧客)
すべての顧客です。したがって、
\pi_{顧客名}(顧客) - \pi_{顧客名}(トランザクション)
私たちが保持したいものはすべてです。最後に、それらの都市を見つける必要があります (簡単にするために、結合演算子 |x| を使用しています)。
\pi_{customer_name, cust_city}((\pi_{customer_name}(customer) - \pi_{customer_name}(transactions)) |x| customer)