0% found this document useful (0 votes)
95 views7 pages

Aggregate Functions

The document discusses various aggregate functions and set operations that can be performed using SQL queries on tables containing customer, deposit, borrow, and branch data. It provides 10 examples of queries using aggregate functions like SUM, COUNT, MAX to calculate totals, counts, maximums. It also provides 7 examples of set operations like UNION, INTERSECT, MINUS performed on the tables to list customers meeting certain criteria.

Uploaded by

pauljose007
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)
95 views7 pages

Aggregate Functions

The document discusses various aggregate functions and set operations that can be performed using SQL queries on tables containing customer, deposit, borrow, and branch data. It provides 10 examples of queries using aggregate functions like SUM, COUNT, MAX to calculate totals, counts, maximums. It also provides 7 examples of set operations like UNION, INTERSECT, MINUS performed on the tables to list customers meeting certain criteria.

Uploaded by

pauljose007
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

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 [Link]=[Link] and
[Link]='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 [Link]=[Link] and
[Link]='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 [Link]=[Link] and


[Link]='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 [Link] 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 [Link],[Link] from deposit d,customer c where [Link]=[Link] and
[Link]='Nagpur'union select [Link],[Link] from borrow b,customer c where [Link]=[Link]
and [Link]='Nagpur';
CNAME

AMT

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

1200

Maduri

2000

Pramod

3300

2)

list all customers who are both depositors and borrowers

Query:
SQL> select [Link] from deposit d intersect select [Link] from borrow b;

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

List all depositors living in Nagpur and having branch in Delhi

SQL> select [Link] from deposit d,customer c where [Link]=[Link] and [Link]='Nagpur'intersect
select [Link] from branch b,deposit d where [Link]=[Link] and [Link]='Delhi';

CNAME

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

4)

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

Query:
SQL> select [Link] from deposit d where [Link]>1000 intersect select [Link] from borrow b
where [Link]<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 [Link] from branch
b,deposit d where [Link]=[Link] and [Link]='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