Consider the banking example we used in lecture: branch (branch-name, branch-cit
ID: 3921104 • Letter: C
Question
Consider the banking example we used in lecture:
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)
Write and execute the following queries in SQL:
1. Find the names of customers on streets with names ending in "Hill“.
2. Print loan data, ordered by decreasing amounts, then increasing loan numbers.
3. Print the names and cities of customers who have a loan at Perryridge branch.
Explanation / Answer
1. Find the names of customers on streets with names ending in "Hill“.
Answer: select customer-name from customer where customer-street like '%Hill';
2. Print loan data, ordered by decreasing amounts, then increasing loan numbers.
Answer: select loan-number, branch-name, amount from loan order by amount desc, loan-number asc;
3. Print the names and cities of customers who have a loan at Perryridge branch.
Answer: select c.customer-name , c.customer-city from customer c, borrower b, loan l where c.customer-name = b.customer-name and b.loan-number = l.loan-number and l.branch-name = 'Perryridge';
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.