數據庫課當中,有一個重要的節點是講述關係代數(Relational Algebra)的查詢(query),感覺挺重要也挺有意思的,現來道例題仔細分析:
Schema: 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)
Q1: Find all loans of over $120
Q2: Find the loan number for each loan of an amount greater than $1200
Q3: Find the names of all customers who have a loan, an account, or both, from the bank
Q4: Find the names of all customers who have a loan at the Perryridge branch but do not have an account at any branch of the bank.
Q5: Find the names of all customers who have a loan at the Perryridge branch (multi-solution).
Q6: Find the largest account balance
Q7: Find the names of all customers who have a loan and an account at bank
Q8: Find the name of all customers who have a loan at the bank and the loan number, as well as loan amount
Q9: Find all customers who have an account from at least the “Downtown” and the “Uptown” branches (multi-solution).
Q10: Find all customers who have an account at all branches located in Brooklyn city.
Q11: Delete all account records in the Perryridge branch.
Q12: Delete all loan records with amount in the range of 0 to 50
Q13: Delete all accounts at branches located in Needham.
Q14: Insert information in the database specifying that Smith has $1200 in account A-973 at the Perryridge branch.
Q15: Provide as a gift for all loan customers in the Perryridge branch, a $200 savings account. Let the loan number serve as the account number for the new savings account.
Q16: Make interest payments by increasing all balances by 5 percent.
Q17: Pay all accounts with balances over $10,000 interest of 6 percent and pay all others 5 percent.