Homework 03¶
3.8¶
Consider the bank database of Figure 3.18, where the primary keys are underlined. Construct the following SQL queries for this relational database.
a. Find the ID of each customer of the bank who has an account but not a loan.
b. Find the ID of each customer who lives on the same street and in the same city as customer '12345'.
c. Find the name of each branch that has at least one customer who has an account in the bank and who lives in "Harrison".
branch(branch name, branch_city, assets)
customer(ID, customer_name, customer_street, customer_city)
loan(loan_number, branch name, amount)
borrower(ID, loan number)
account(account_number, branch_name, balance)
depositor(ID, account_number)
(a)
(b)
SQL | |
---|---|
©
SQL | |
---|---|
3.9¶
Consider the relational database of Figure 3.19, where the primary keys are underlined. Give an expression in SQL for each of the following queries.
a. Find the ID, name, and city of residence of each employee who works for "First Bank Corporation".
b. Find the ID, name, and city of residence of each employee who works for "First Bank Corporation" and earns more than $10000.
c. Find the ID of each employee who does not work for "First Bank Corporation".
d. Find the ID of each employee who earns more than every employee of "Small Bank Corporation".
e. Assume that companies may be located in several cities. Find the name of each company that is located in every city in which "Small Bank Corporation" is located.
f. Find the name of the company that has the most employees (or companies, in the case where there is a tie for the most).
g. Find the name of each company whose employees earn a higher salary, on average, than the average salary at "First Bank Corporation".
employee (ID, person_name, street, city)
works (ID, company_name, salary)
company (company_name, city)
manages (ID, manager_id)
(a)
SQL | |
---|---|
(b)
SQL | |
---|---|
©
(d)
SQL | |
---|---|
(e)
SQL | |
---|---|
(f)
SQL | |
---|---|
(g)
SQL | |
---|---|