Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views

Assignment No 2 SQL

Uploaded by

wacih58121
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Assignment No 2 SQL

Uploaded by

wacih58121
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Assignment 2

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

branch varchar(25) primary key,

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

create table branch_36

SQL> select *from branch_36;

BRANCH_NAME BRANCH_CITY ASSETS

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

Akurdi Pune 11658696

Nigdi Nigdi 344231

GAdityain Bank Padoli 3544126

SQL> select * from account_36;

ACC_NO BRANCH_NAME BALANCE

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

1 Nigdi 12664

2 Akurdi 46532

3 GAdityain Bank 79536

SQL> select* from customer_36;

CUST_NAME CUST_STREE CUST_CITY

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

Gaurav Jagtap Walhekar wadi Pune

Aditya Joshi Ravet Nigdi

MaheshwarSamrat Chouk Padoli

SQL> select * from depositor_36;

CUST_NAME ACC_NO

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

Gaurav Jagtap 2

Aditya Joshi 1
Maheshwar3

SQL> select * from loan_36;

LOAN_NO BRANCH_NAME AMOUNT

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

123 Nigdi 52694

456 Akurdi 12645

1169 GAdityain Bank 589674

SQL> select * from borrower_36;

CUST_NAME LOAN_NO

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

Gaurav Jagtap 123

Maheshwar456

Aditya Joshi 1169

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

SQL> select branch_name from loan_36;

BRANCH_NAME

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

Nigdi

Akurdi

GAdityain Bank

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

SQL> select loan_no from loan where amount > 12000;

no rows selected

SQL> select loan_no from loan where amount > 10000;

no rows selected

SQL> select loan_no from loan_36 where amount > 10000;

LOAN_NO

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

123
456

1169

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_36 c

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

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

CUST_NAME LOAN_NO AMOUNT

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

Gaurav Jagtap 123 52694

Maheshwar456 12645

Aditya Joshi 1169 589674

SQL> select c.*

2 from customer_36 c

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

4 join loan_36 l on b.loan_no = l

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

SQL> select * from customer_36

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

4 join loan_36 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

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

Maheshwar Samrat Chouk Padoli

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

SQL> select distinct cust_name from depositor_36 union select distinct cust_name from

borrower_36;

CUST_NAME
------------------------------

Aditya Joshi

Mahesh

Gaurav Jagtap

SQL> select d.cust_name

2 from depositor_36 d

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

CUST_NAME

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

Gaurav Jagtap

Mahesh

Aditya Joshi

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

SQL> select d.cust_name

2 from depositor_36 d

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

no rows selected

Q8. Find average account balance at Akurdi branch.

SQL> select avg(a.balance) as avg_balance

2 from account_36 a

3 where a.branch_name = 'Akurdi';

AVG_BALANCE

-----------

46532

Q9. Find the average account balance at each branch

SQL> select branch_name , avg(balance) as avg_balance

2 from account_36

3 group by branch_name;

BRANCH_NAME AVG_BALANCE

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

Nigdi 12664
GAdityain Bank 79536

Akurdi 46532

Q10. Find no. of depositors at each branch.

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

2 from account_36 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 1

GAdityain Bank 1

Akurdi 1

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

SQL> select branch_name

2 from account_36

3 group by branch_name

4 having avg(balance)>12000;

BRANCH_NAME

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

Nigdi

GAdityain Bank

Akurdi

Q12. Find number of tuples in customer relation.

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

NUM_TUPLES

----------

Q13. Calculate total loan amount given by bank.

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

TOTAL_AMOUNT

------------
69260

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

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

0 rows deleted.

Q15. Delete all tuples at every branch located in Nigdi.

SQL> delete from branch_36 where branch_city = 'Padoli';

delete from branch_36 where branch_city = 'Padoli'

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

delete from branch_36 where branch_city = 'Pune'

Q.16. Create synonym for customer table as cust

SQL> create synonym cust for customer_36;

Synonym created.

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

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

Table created.

SQL> select * from student_36;

ROLL_NO NAME

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

1 Aditya

2 Shyam

3 Prathmesh

4 Maheshwar

5 Rohan

6 Ganesh

6 rows selected.

You might also like