Lab 2
Lab 2
Introduction to Database
Banking Example
branch (branch-name, branch-city, assets)
http://www.cs.kent.edu/~nruan/bank_db.sql
http://www.cs.kent.edu/~nruan/bank_data.sql
Access MySQL
>mysql –u [username] –p
>Enter password:[password]
Query
To find all loan number for loans made at the Perryridge
branch with loan amounts greater than $1100.
Find the customer names and their loan numbers for all customers
having a loan at some branch.
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);
Nested Subquery
Find the names of all branches that have greater assets
than all branches located in Horseneck.
select branch_name
from branch
where assets > all
(select assets
from branch
where branch_city = ‘Horseneck’);
Create View (new feature in
mysql 5.0)
A view consisting of branches and their customers
update account
set balance = balance 1.07
where balance > 800;
update account
set balance = balance 1.08
where balance 800;
Modification of Database
Increase all accounts with balances over $700 by 6%, all
other accounts receive 5%.
update account
set balance =case
when balance <= 700 then balance *1.05
else balance * 1.06
end;
Modification of Database
Delete the record of all accounts with balances below the
average at the bank.
delete from account
where balance < (select avg (balance) from account);