0% found this document useful (0 votes)
21 views

Assignment No 2 Dbmsss

Uploaded by

wacih58121
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Assignment No 2 Dbmsss

Uploaded by

wacih58121
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Assignment 2

Syrle22

SQL> create table branch_22 , branch varchar(25) primary key, branch_city varchar(15), assets
varchar(10));

branch varchar(25) primary key,

SQL> select *from branch_22;

BRANCH_NAME BRANCH_CITY ASSETS

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

Akurdi Pune 11888888

Nigdi Nigdi 684512

ShivajiBank Latur 7894512

SQL> select * from account_36;

ACC_NO BRANCH_NAME BALANCE

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

1 Nigdi 12664

2 Akurdi 46532

3 ShivajiBank 79536

SQL> select* from customer_22;

CUST_NAME CUST_STREE CUST_CITY

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

Ajinkya bharti KothrudPune

Ujwal Rajpoot Ravet Nigdi

Rajiv_gandhi Chouk Latur

SQL> select * from depositor_36;

CUST_NAME ACC_NO

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

Ajinkya bharti 1

Ujwal Rajpoot 2

Pratikk 3
SQL> select * from loan_22;

LOAN_NO BRANCH_NAME AMOUNT

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

345 Nigdi 15000

685 Akurdi 120000

909 ShivajiBank 500000

SQL> select * from borrower_22;

CUST_NAME LOAN_NO

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

Ajinkya bharti 345

Pratikk 685

Ujwal Rajpoot 909

Q.1 Find the names of all branches in loan relation .

SQL> select branch_name from loan_22;

BRANCH_NAME

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

Nigdi

Akurdi

ShivajiBank

Q.2 Find all loan numbers for loans made at Akurdi Branch with loan amount > 1200000

SQL> select loan_no from loan_22 where amount > 1200000;

no rows selected

SQL> select loan_no from loan_22 where amount > 10000;

LOAN_NO

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

345

685

909

Q3. Find all customers who have a loan from bank. Find their names,loan_no and loan

amount.
SQL> select c.cust_name,b.loan_no,l.amount

2 from customer_22 c

3 join borrower_22 b on c.cust_name=b.cust_name

4 join loan_22 l on b.loan_no = l.loan_no;

CUST_NAME LOAN_NO AMOUNT

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

Ajinkya bharti 345 15000

Pratikk 685 120000

Ujwal Rajpoot 909 500000

SQL> select c.*

2 from customer_22 c

3 join borrower_22 b on c.cust_name=b.cust_name

4 join loan_22 l on b.loan_no = l

Q4..Find all customers who have an account or loan or both at bank

SQL> select * from customer_22

3 join borrower_22 b on c.cust_name=b.cust_name

4 join loan_22 l on b.loan_no = l.loan_no

5 where l.branch_name ='Akurdi'

6 order by c.cust_name;

CUST_NAME CUST_STREE CUST_CITY

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

Pratikk Samrat Chouk Latur

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

SQL> select distinct cust_name from depositor_22 union select distinct cust_name from

borrower_22;

CUST_NAME

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

Ajinkya Bharti

Ujwal Rajpoot

Pratikk
SQL> select d.cust_name

2 from depositor_22 d

3 join borrower_22 b on d.cust_name = b.cust_name;

CUST_NAME

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

Ajinkya bharti

Ujwal Rajpoot

Pratikk

Q7. Find all customer who have account but no loan at the bank.

SQL> select d.cust_name

2 from depositor_22 d

3 where d.cust_name not in (select b.cust_name from borrower_22 b);

no rows selected

Q8. Find average account balance at Akurdi branch.

SQL> select avg(a.balance) as avg_balance

2 from account_22 a

3 where a.branch_name = 'Akurdi';

AVG_BALANCE

-----------

45684

Q9. Find the average account balance at each branch

SQL> select branch_name , avg(balance) as avg_balance

2 from account_22

3 group by branch_name;

BRANCH_NAME AVG_BALANCE

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

Nigdi 24891

ShivajiBank 12836

Akurdi 45684

Q10. Find no. of depositors at each branch.

SQL> select a.branch_name,count(d.cust_name) as num_depositors


2 from account_22 a

3 left join depositor_36 d on a.acc_no = d.acc_no

4 group by a.branch_name;

BRANCH_NAME NUM_DEPOSITORS

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

Nigdi 2

ShivajiBank 2

Akurdi 2

Q11. Find the branches where average account balance > 12000.

SQL> select branch_name

2 from account_22

3 group by branch_name

4 having avg(balance)>12000;

BRANCH_NAME

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

Nigdi

ShivajiBank

Akurdi

Q12. Find number of tuples in customer relation.

SQL> select count(*) as num_tuples from customer_22;

NUM_TUPLES

----------

Q13. Calculate total loan amount given by bank.

SQL> select sum(amount) as total_amount from loan_22;

TOTAL_AMOUNT

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

786250

Q14. Delete all loans with loan amount between 1300 and 1500.

SQL> delete from loan_22 where amount between 1300 and 1500;

0 rows deleted.
Q15. Delete all tuples at every branch located in Nigdi.

SQL> delete from branch_22 where branch_city = 'Latur';

delete from branch_22 where branch_city = 'Latur'

SQL> delete from branch_22 where branch_city = 'Pune';

delete from branch_22 where branch_city = 'Pune'

Q.16. Create synonym for customer table as cust

SQL> create synonym cust for customer_22;

Synonym created.

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

SQL> create table student_22(roll_no number primary key,name varchar(20));

Table created.

SQL> select * from student_22;

ROLL_NO NAME

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

1 Yash

2 Pranav

3 Aryan

4 Sanskruti

5 Riya

6 Pratik

6 rows selected.

You might also like