Labfile ADBMS
Labfile ADBMS
5. Find all loan numbers for loans made at the Perry 11-SEP-24
ridge branch with loan amounts greater than $1200.
7. Find all loan numbers that appear in the loan relation 23-SEP-24
with null values for amount.
12. Find all customer who have both a loan and an 25-SEP-24
account at the bank.
13. Find all customer who have an account but no loan at 25-SEP-24
the bank
14. Find total account balance at each branch. 25-SEP-24
17. Delete all loans amounts between 1300 and 1500. 30-SEP-24
18. Delete all account tuples at every branch located in 30-SEP-24
Needham.
19. Insert a new record into account where account no. 30-SEP-24
A-9732 at the Perry Ridge Branch & that is has a
balance 0.
20. Update balance Value of the account table by 30-SEP-24
Mul plica on of 1.05 where balance is greater than
equal to 700.
22. Find the average balance for each customer who lives 30-SEP-24
in Harrison and has at least three accounts.
25. For all customers who have a loan from the bank, find 30-SEP-24
their names, loan numbers, and loan amount with
renaming the tables.
emp table
Bank database Schema:
Account1 table schema:
Account1_schema=(account_number; branch_name, balance)
Sql query:
Create table account1(account_number char(15),
Branch_name varchar(15),
Balance numeric(12, 2),
Primary key(account_number));
SQL :
select customer_name, borrower.loan_number, amount
from borrower, loan
where borrower.loan_number = loan.loan_number;
2. Find the customer names, loan numbers, and loan amounts for all loans at the Perryridge
branch.
SQL:
select customer_name, Borrower.loan_number, amount
from Borrower, loan
where Borrower.loan_number = loan.loan_number and
branch_name = "Perryridge";
3. Find the names of all branches that have assets greater than at least one branch located in
Brooklyn.
SQL:
select distinct T.branch_name
from branch as T, branch as S
where T.assets > S.assets and S.branch_city = "Brooklyn";
4. Find the names of all branches in the loan rela on
SQL : select branch_name from loan;
5. Find all loan numbers for loans made at the Perryridge branch with loan amounts greater
than $1200.
SQL:
select loan_number
from loan
where branch_name = "Perryridge" and amount > 1200;
7. Find all loan numbers that appear in the loan relation with null values for amount.
SQL: select loan_number
from loan
where amount is null;
8. Provide an SQL with example which will rename the relational name.
SQL:
select customer_name, borrower.loan_number as loan_id, amount
from borrower, loan
where borrower.loan_number = loan.loan_number;
9. Write the name of all customers whose street address includes the substring ‘Main’.
select customer_name
from customer
where customer_street like '%Main%';
SQL :
branch_name = "Perryridge"
order by customer_name;
11. Select operation ,union, intersection and set difference.
UNION:
SQL:
union
Intersect:
SQL:
SELECT DISTINCT d.customer_name
FROM depositor d
INNER JOIN borrower b ON d.customer_name = b.customer_name;
Difference:
SQL:
select distinct customer_name from depositor where customer_name not in (select
customer_name from borrower);
12. Find all customer who have both a loan and an account at the bank.
SQL :
select distinct customer_name from borrower where customer_name in (select
customer_name from depositor);
13. Find all customer who have an account but no loan at the bank
SQL :
select depositor.customer_name as d_CN from depositor
left join borrower on depositor.customer_name = borrower.customer_name
where borrower.customer_name is null;
14. Find total account balance at each
branch.
SQL :
select branch_name, sum(balance)
from account1
group by branch_name;
Before:
After:
After query:
A er query:
20. Update balance Value of the account table by Muliplica on of 1.05 where balance is greater
than equal to 700.
SQL:
update account set balance = balance * 1.05 where balance >= 1000
Before:
A er query:
21. Create account table with two a ributes. a.) Account no of char type. b.) Balance of int type.
SQL:
create table Account2 (account_number char(15), balance integer, primary
key(account_number));
22. Find all customers who do have a loan at the bank, but do not have an account at the
bank.
SQL :
SELECT DISTINCT borrower.customer_name
FROM borrower
LEFT JOIN depositor ON borrower.customer_name = depositor.customer_name
WHERE depositor.customer_name IS NULL;
23. Find the average balance for each customer who lives in Harrison and has at least three
accounts.
SQL :
25. For all customers who have a loan from the bank, find their names, loan numbers, and
loan amount with renaming the tables.
SQL :
select customer_name, T.loan_number, S.amount
from borrower as T, loan as S
where T.loan_number = S.loan_number;
Employee Database
CREATE TABLE emp (
SQL: select ename, sal from emp where sal>1000 and sal<3000;
4. Write a query to select emp, employee name and salary where salary is
greater than or equal to 2000 and add 500 Rs extra and display.
SQL:
select ename, sal+500 from emp where sal>=2000 ;
5. Write a query to find ename and salary from EMP table and salary*100 with renaming of
column.
SQL:
select ename, sal, sal*100 from emp ;
6. Write a query to find employee name and salary from EMP table ordered
by salary.
SQL:
select ename, sal from emp order by sal;
7. Write a query to display all aggrega on opera on in the EMP table for
the a ribute salary.
SQL:
select avg(sal) from emp;