Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Chapter 3: SQL Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use Figure 3.1: Database Schema branch (branch_name, branch_city, assets) customer (customer_name, customer_street, customer_city) loan (loan_number, branch_name, amount) borrower (customer_name, loan_number) account (account_number, branch_name, balance) depositor (customer_name, account_number) Database System Concepts, 5th Ed., June 2006 3.2 ©Silberschatz, Korth and Sudarshan Set Operations Find all customers who have a loan, an account, or both: (select customer_name from depositor) union (select customer_name from borrower) Find all customers who have both a loan and an account. (select customer_name from depositor) intersect (select customer_name from borrower) Find all customers who have an account but no loan. (select customer_name from depositor) except (select customer_name from borrower) Database System Concepts, 5th Ed., June 2006 3.3 ©Silberschatz, Korth and Sudarshan “In” Construct Find all customers who have both an account and a loan at the bank. select distinct customer_name from borrower where customer_name in (select customer_name from depositor ) Find all customers who have a loan at the bank but do not have an account at the bank select distinct customer_name from borrower where customer_name not in (select customer_name from depositor ) Database System Concepts, 5th Ed., June 2006 3.4 ©Silberschatz, Korth and Sudarshan “Some” Construct Find all branches that have greater assets than some branch located in Brooklyn. Same query using > some clause select branch_name from branch where assets > some (select assets from branch where branch_city = 'Brooklyn') Database System Concepts, 5th Ed., June 2006 3.5 ©Silberschatz, Korth and Sudarshan “All” Construct Find the names of all branches that have greater assets than all branches located in Brooklyn. select branch_name from branch where assets > all (select assets from branch where branch_city = 'Brooklyn') Database System Concepts, 5th Ed., June 2006 3.6 ©Silberschatz, Korth and Sudarshan