You are on page 1of 7

AGGREGATE FUNCTIONS

Use tables Deposit, borrow, branch, customer

1)

Calculate total deposit amount of the customers

Query:
SQL> select sum(amt)"Total"from deposit;

Total
--------------19500

2)

Calculate the total loan taken by the customers

Query:

SQL> select sum(amt)"Total"from borrow;

Total
---------11000

3)

Find the total loan taken from Ajne branch

Query:
SQL> select sum(amt)"Total"from borrow where bname='AJNE';
Total

---------5000
4)
Calculate the total deposit of the customers who have taken an account on
27/mar/2011
Query:
SQL> select sum(amt)"Total" from deposit where adate='27-mar-2011';
Total
---------3300
5)

calculate the total deposit amount of the customers living in Nagpur city

Query:
SQL> select sum(amt)"Total" from deposit d,customer c where c.cname=d.cname and
c.lcity='Nagpur';
Total
---------4500
6)

Calculate the total deposit amount of the customers having Delhi as the branch city.

Query:
SQL> select sum(amt)"Total" from deposit d,branch b where d.bname=b.bname and
b.bcity='Delhi';
Total
---------4700

7)

Find the maximum deposit of customers living in Nagpur city

Query:

SQL> select max(amt)"Maximum" from deposit d,customer c where c.cname=d.cname and


c.lcity='Nagpur';

Maximum
----------------3300

8) Find Maximum loan amount taken from the ajne branch

Query:
SQL> select max(amt)"Maximum" from borrow where bname='AJNE';
Maximum
---------5000
9) find the total no. of branch city
Query:
SQL> select count(distinct(bcity))"Count" from branch;
Count
---------4
10) find the total no.of customers
Query:
SQL> select count(cname)"Count" from customer;
Count
---------7

PROGRAM: 9
DATE: 25/04/2014
SET OPERATIONS

use borrow and deposit table


1.
list all customers along with their amount(loan/deposit) who are either borrowers or
depositors

Query:
SQL> select cname,amt from borrow union select cname,amt from deposit;

CNAME

AMT

-------------------- ---------Anil

1000

Maduri

1200

Maduri

2000

Mehul

3500

Mehul

5000

Naren

3300

Pramod

3300

Sandeep

2200

Sunil

3000

Sunil

5000

1)
list all customers along with their amount(loan/deposit) who are either borrowers or
depositors and living in city Nagpur.

Query:
SQL> select d.cname,d.amt from deposit d,customer c where d.cname=c.cname and
c.lcity='Nagpur'union select b.cname,b.amt from borrow b,customer c where b.cname=c.cname
and c.lcity='Nagpur';
CNAME

AMT

-------------------- ---------Maduri

1200

Maduri

2000

Pramod

3300

2)

list all customers who are both depositors and borrowers

Query:
SQL> select d.cname from deposit d intersect select b.cname from borrow b;

CNAME
-------------------Anil
Maduri
Mehul
Sunil
3)

List all depositors living in Nagpur and having branch in Delhi

SQL> select d.cname from deposit d,customer c where d.cname=c.cname and c.lcity='Nagpur'intersect
select d.cname from branch b,deposit d where d.bname=b.bname and b.bcity='Delhi';

CNAME

-------------------Maduri

4)

List all customers having deposit greater than 1000 and loan less than 5000

Query:
SQL> select d.cname from deposit d where d.amt>1000 intersect select b.cname from borrow b
where b.amt<5000;
CNAME
-------------------Maduri
Sunil
5)

List the cities which are either branch city of anil or living city of Sunil

Query:
SQL> select lcity from customer where cname='Sunil' union select b.bcity from branch
b,deposit d where b.bname=d.bname and d.cname='Anil';

LCITY
-------------------Delhi
Nagpur
7) List all customers who are depositors but not borrowers
Query:
SQL> select cname from deposit minus select cname from borrow;

CNAME
-------------------Naren

Pramod
Sandeep

You might also like