Professional Documents
Culture Documents
Assignment 2
Assignment 2
TABLES :
1) Account
SQL> select * from Account;
7 rows selected.
2) Branch
BRANCH_NAME BRANCH_CITY
--------------- ---------------
Parner Parner
Dhule Pimpalner
Nanded Kinwad
Akurdi Akurdi
Parbhani Parbhani
Nashik Ozar
6 rows selected.
3) Customer
SQL> select * from Customer;
7 rows selected.
4) Depositor
SQL> select * from Depositor;
CUST_NAME ACC_NO
------------------------------ ----------
Abhi 122059
Bhavesh 122046
Atharv 122019
Onkar 122057
Sudharma 122018
Shubham 122002
Abhishek 122042
7 rows selected.
5) Loan
SQL> select * from Loan;
6) Borrower
SQL> select * from Borrower;
CUST_NAME LOAN_NO
------------------------------ ----------
Onkar 12346
Abhishek 12347
Abhi 12348
Shubham 12345
Q1. Find the names of all branches in loan relation.
BRANCH_NAME
---------------
Parner
Akurdi
Akurdi
Parner
Q2. Find all loan numbers for loans made at Akurdi Branch with loan amount > 12000.
SQL> select loan_no from Loan where branch_name = 'Akurdi' AND amount > 12000;
LOAN_NO
----------
12346
Q3. Find all customers who have a loan from bank. Find their names, loan_no and loan amount.
SQL> select b.cust_name,b.loan_no,l.amount from Loan l inner join Borrower b on l.loan_no = b.loan_no;
Q4. List all customers in alphabetical order who have loan from Akurdi branch.
SQL> select cust_name from Borrower where loan_no in (select loan_no from Loan where branch_name = 'Akurdi')
order by cust_name;
CUST_NAME
------------------------------
Abhishek
Onkar
Q5. Find all customers who have an account or loan or both at bank.
CUST_NAME
------------------------------
Abhi
Bhavesh
Atharv
Onkar
Sudharma
Shubham
Abhishek
Q6. Find all customers who have both account and loan at bank.
CUST_NAME
------------------------------
Onkar
Abhishek
Abhi
Shubham
Q7. Find all customer who have account but no loan at the bank.
SQL> select cust_name from Depositor where cust_name not in (select cust_name from Borrower);
CUST_NAME
------------------------------
Bhavesh
Sudharma
Atharv
Q8. Find average account balance at Akurdi branch.
AVG(BALANCE)
------------
11333.3333
SQL> select b.branch_name,AVG(a.balance) from Account a full join Branch b on a.branch_name = b.branch_name
group by b.branch_name order by AVG(a.balance);
BRANCH_NAME AVG(A.BALANCE)
--------------- --------------
Akurdi 11333.3333
Dhule 24000
Parner 28350
Nanded 35000
Parbhani
Nashik
6 rows selected.
SQL> select a.branch_name,COUNT(a.branch_name) from Depositor d left join Account a on a.Acc_no = d.Acc_no
group by a.branch_name;
BRANCH_NAME COUNT(A.BRANCH_NAME)
--------------- --------------------
Parner 2
Dhule 1
Nanded 1
Akurdi 3
Q11. Find the branches where average account balance > 12000.
SQL> select branch_name,AVG(balance) from Account having AVG(balance) > 12000 group by branch_name;
BRANCH_NAME AVG(BALANCE)
--------------- ------------
Parner 28350
Dhule 24000
Nanded 35000
COUNT(*)
----------
SUM(AMOUNT)
-----------
96000
Q14. Delete all loans with loan amount between 13000 and 18000.
SQL> delete from Borrower where loan_no in (select loan_no from Loan where amount between 13000 and 18000);
1 row deleted.
SQL> delete from Loan where amount between 13000 and 18000;
1 row deleted.
Q15. Delete all tuples at every branch located in Nigdi.
SQL> delete from borrower where loan_no in (select loan_no from Loan where branch_name = 'Akurdi');
2 rows deleted.
2 rows deleted.
SQL> delete from Depositor where acc_no in (select Acc_no from Account where branch_name = 'Akurdi');
3 rows deleted.
3 rows deleted.
1 row deleted.
Synonym created.
7 rows selected.
Q.17. Create sequence roll_seq and use in student table for roll_no column.
Sequence created.
3 name varchar(30));
Table created.
ROLL_NO NAME
---------- ------------------------------
1 Abhi
2 Bhavesh
3 Atharv
4 Shubham
5 Sudharma