Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

ASSIGNMENT 2 Name : Abhijeet Dilip Date.

Roll No. : SYCOA59

TABLES :

1) Account
SQL> select * from Account;

ACC_NO BRANCH_NAME BALANCE


---------- --------------- ----------
122059 Parner 12000
122046 Dhule 24000
122019 Nanded 35000
122057 Akurdi 14500
122018 Akurdi 5500
122002 Parner 44700
122042 Akurdi 14000

7 rows selected.

2) Branch

SQL> select * from 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;

CUST_NAME CUST_STREET CUST_CITY


------------------------------ ------------ ----------
Abhi College Road Parner
Bhavesh Satana Road Pimpalner
Atharv Nanded Road Kinwad
Onkar College Road Akurdi
Sudharma College Road Akurdi
Shubham Shirur Road Parner
Abhishek Akurdi Road Aundh

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;

LOAN_NO BRANCH_NAME AMOUNT


---------- --------------- ----------
12345 Parner 50000
12346 Akurdi 20000
12347 Akurdi 11000
12348 Parner 15000

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.

SQL> select branch_name from Loan;

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;

CUST_NAME LOAN_NO AMOUNT

------------------------------ ---------- ----------

Shubham 12345 50000

Onkar 12346 20000

Abhishek 12347 11000

Abhi 12348 15000

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.

SQL> select cust_name from Depositor;

CUST_NAME

------------------------------

Abhi

Bhavesh

Atharv

Onkar

Sudharma

Shubham

Abhishek

Q6. Find all customers who have both account and loan at bank.

SQL> select cust_name from borrower;

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.

SQL> select AVG(balance) from Account where branch_name = 'Akurdi';

AVG(BALANCE)

------------

11333.3333

Q9. Find the average account balance at each branch.

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.

Q10. Find no. of depositors at each branch.

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

Q12. Find number of tuples in customer relation.

SQL> select COUNT(*) from Customer;

COUNT(*)

----------

Q13. Calculate total loan amount given by bank.

SQL> select SUM(amount) from loan;

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.

SQL> delete from Loan where branch_name = 'Akurdi';

2 rows deleted.

SQL> delete from Depositor where acc_no in (select Acc_no from Account where branch_name = 'Akurdi');

3 rows deleted.

SQL> delete from Account where branch_name = 'Akurdi';

3 rows deleted.

SQL> delete from Branch where branch_name = 'Akurdi';

1 row deleted.

Q.16. Create synonym for customer table as cust.

SQL> create synonym cust for Customer;

Synonym created.

SQL> select * from cust;

CUST_NAME CUST_STREET CUST_CITY

------------------------------ ------------ ----------

Abhi College Road Parner

Bhavesh Satana Road Pimpalner

Atharv Nanded Road Kinwad

Onkar College Road Akurdi


Sudharma College Road Akurdi

Shubham Shirur Road Parner

Abhishek Akurdi Road Aundh

7 rows selected.

Q.17. Create sequence roll_seq and use in student table for roll_no column.

SQL> create sequence roll_seq start with 1 increment by 1;

Sequence created.

SQL> create table student(

2 roll_no number default roll_seq.nextval primary key,

3 name varchar(30));

Table created.

SQL> select * from student;

ROLL_NO NAME

---------- ------------------------------

1 Abhi

2 Bhavesh

3 Atharv

4 Shubham

5 Sudharma

You might also like