SlideShare a Scribd company logo
Welcome to my Presentation
Name: Shahadat Hossain
Id: 133-15-3031
Topic: Aggregate Functions
shahadat3031@gmail.com
Aggregate Function:
Aggregate functions are functions that take a collection of values as
input and return a single value.
 Behavior of Aggregate Functions:
Operates - on a single column
Return - a single value.
Used only in the SELECT list and in the HAVING clause.
Types of SQL Aggregate Functions:
Aggregate
Functions:
Max()
Min()
Avg()
Sum()
Input to Aggregate Function
• SUM and AVG :
 Operates only on collections of numbers .
• MIN , MAX and COUNT
 Operates on collection of numeric and non-numeric
data types.
Each function eliminates NULL values and operates on
Non- null values.
USE OF SUM()
Returns: The sum of the values in a specified
column.
Example: Find the total/sum of the Managers
salary
Query:
SELECT SUM( salary) AS sum_salary
FROM Staff
WHERE Staff.position = ‘Manager’;
Result:
sum_salary
54000.00
USE OF AVG()
Returns: The average of the values in a specified column.
Example: Find the average of the Project Managers salary .
Query:
SELECT AVG(ALL salary) AS avg_salary
FROM Staff
WHERE Staff.position = ‘Project Manager’;
Result :
avg_salary
11000.00
Staff
sno fname lname salary position
SL100 John White 30000.00 Manager
SL101 Susan Brand 24000.00 Manager
SL102 David Ford 12000.00 Project
Manager
SL103 Ann Beech 12000.00 Project
Manager
SL104 Mary Howe 9000.00 Project
Manager
MIN() and MAX()
Returns: MIN() returns the smallest value of a column.
MAX() returns the largest value of a column.
Example: Find the minimum and maximum staff salary.
Query:
SELECT MIN( salary) AS min_salary, MAX (salary) AS
max_salary
FROM Staff;
Result: min_salary max_salary
9000.00 30000.00
USE OF COUNT()
Returns: The number of values in the specified column.
Example: Count number of staffs who are Manager.
Query: SELECT COUNT(sno) AS sno_count
FROM Staff
WHERE Staff.position = ‘Manager’;
Result:
sno_count
2
Use of COUNT() and SUM()
Example: Find the total number of Managers and the sum of there
salary.
Query: SELECT COUNT( sno) AS sno_count , SUM(salary) AS
sum_salary
From Staff
WHERE Staff.position = ‘Manager’;
sno fname lname salary position
SL100 John White 30000.00 Manager
SL101 Susan Brand 24000.00 Manager
SUMCOUNT
COUNT() and SUM() continued
• Result:
sno_count sum_salary
2 54000.00
Aggregate Function - Database
Aggregate Function - Database

More Related Content

What's hot (20)

PPTX
SQL Commands
Sachidananda M H
 
PPTX
Structured Query Language
Surkhab Shelly
 
PDF
PL/SQL TRIGGERS
Lakshman Basnet
 
PPTX
SQL commands
GirdharRatne
 
PPTX
Unit 2 oracle9i
DrkhanchanaR
 
PPTX
Sql Constraints
I L0V3 CODING DR
 
PPT
Abstract class
Tony Nguyen
 
PPTX
Aggregate function
Rayhan Chowdhury
 
PPTX
Sql subquery
Raveena Thakur
 
PPTX
Sql and Sql commands
Knowledge Center Computer
 
PPT
Advanced sql
Dhani Ahmad
 
PPT
Sql join
Vikas Gupta
 
PPT
MYSQL Aggregate Functions
Leroy Blair
 
PPT
Query optimization
dixitdavey
 
PPTX
STRUCTURE OF SQL QUERIES
VENNILAV6
 
PPTX
Advance Java Topics (J2EE)
slire
 
PPTX
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
PPT
1. Introduction to DBMS
koolkampus
 
PPTX
Generalization and specialization
Knowledge Center Computer
 
PPTX
DDL And DML
pnp @in
 
SQL Commands
Sachidananda M H
 
Structured Query Language
Surkhab Shelly
 
PL/SQL TRIGGERS
Lakshman Basnet
 
SQL commands
GirdharRatne
 
Unit 2 oracle9i
DrkhanchanaR
 
Sql Constraints
I L0V3 CODING DR
 
Abstract class
Tony Nguyen
 
Aggregate function
Rayhan Chowdhury
 
Sql subquery
Raveena Thakur
 
Sql and Sql commands
Knowledge Center Computer
 
Advanced sql
Dhani Ahmad
 
Sql join
Vikas Gupta
 
MYSQL Aggregate Functions
Leroy Blair
 
Query optimization
dixitdavey
 
STRUCTURE OF SQL QUERIES
VENNILAV6
 
Advance Java Topics (J2EE)
slire
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
1. Introduction to DBMS
koolkampus
 
Generalization and specialization
Knowledge Center Computer
 
DDL And DML
pnp @in
 

Viewers also liked (20)

PPT
PHP mysql Aggregate functions
Mudasir Syed
 
PPT
Aggregate Functions,Final
mukesh24pandey
 
PPT
Aggregating Data Using Group Functions
Salman Memon
 
PPTX
Sql Basics And Advanced
rainynovember12
 
PDF
Agreggates i
Claudia Gomez
 
PPT
Dbms4
Suleman Mohd
 
PPTX
Cellular Telephone Networks 2008
Francisco Villegas
 
PDF
namecard
? ?
 
PDF
7 relational database design algorithms and further dependencies
Kumar
 
PPTX
Cellular Telephone Systems
Shantanu Krishna
 
PPT
Unit05 dbms
arnold 7490
 
PPT
Relational Algebra
guest20b0b3
 
PPTX
New Perspectives: Access.03
Anna Stirling
 
PPT
Relational Algebra-Database Systems
jakodongo
 
PPTX
Normalization
Google Student Ambassador
 
DOC
SQL Joins
Paul Harkins
 
PPTX
Sql joins
Gaurav Dhanwant
 
PPT
functional dependencies with example
Siddhi Viradiya
 
PDF
Basic structures in vhdl
Raj Mohan
 
PHP mysql Aggregate functions
Mudasir Syed
 
Aggregate Functions,Final
mukesh24pandey
 
Aggregating Data Using Group Functions
Salman Memon
 
Sql Basics And Advanced
rainynovember12
 
Agreggates i
Claudia Gomez
 
Cellular Telephone Networks 2008
Francisco Villegas
 
namecard
? ?
 
7 relational database design algorithms and further dependencies
Kumar
 
Cellular Telephone Systems
Shantanu Krishna
 
Unit05 dbms
arnold 7490
 
Relational Algebra
guest20b0b3
 
New Perspectives: Access.03
Anna Stirling
 
Relational Algebra-Database Systems
jakodongo
 
SQL Joins
Paul Harkins
 
Sql joins
Gaurav Dhanwant
 
functional dependencies with example
Siddhi Viradiya
 
Basic structures in vhdl
Raj Mohan
 
Ad

Similar to Aggregate Function - Database (20)

PPTX
AGGREGATE FUNCTION.pptx
Anusha sivakumar
 
PPTX
aggregatefunction-220420051702.pptx aggregate
sadiariasat10
 
PDF
SQL-AGG-FUN.pdfiiiijuyyttfffgyyuyyyyyhhh
NaveeN547338
 
PPTX
SQL.pptx
MrHello6
 
PPT
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
अभिषेक शर्मा
 
DOCX
Database Query Using SQL_ip.docx
VandanaGoyal21
 
PPTX
V22 function-1
Dhirendra Chauhan
 
PDF
Introduction to oracle functions
Nitesh Singh
 
PPTX
Lecture 8 DML3 aggregate functions in DB.pptx
imranahmadrana28
 
PPTX
MS Sql Server: Doing Calculations With Functions
DataminingTools Inc
 
PPTX
MS SQLSERVER:Doing Calculations With Functions
sqlserver content
 
PPTX
MS SQL SERVER: Doing Calculations With Functions
sqlserver content
 
PPTX
database_set_operations_&_function.pptx
tanvirkhanfahim
 
PPTX
Sql FUNCTIONS
Abrar ali
 
PDF
Sql group functions
Vivek Singh
 
PPTX
sql function(ppt)
Ankit Dubey
 
RTF
Sql functions
ilias ahmed
 
PDF
MySQL-commands.pdf
ssuserc5aa74
 
PPTX
DBMS: Week 07 - Advanced SQL Queries in MySQL
RashidFaridChishti
 
PDF
Sql wksht-3
Mukesh Tekwani
 
AGGREGATE FUNCTION.pptx
Anusha sivakumar
 
aggregatefunction-220420051702.pptx aggregate
sadiariasat10
 
SQL-AGG-FUN.pdfiiiijuyyttfffgyyuyyyyyhhh
NaveeN547338
 
SQL.pptx
MrHello6
 
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
अभिषेक शर्मा
 
Database Query Using SQL_ip.docx
VandanaGoyal21
 
V22 function-1
Dhirendra Chauhan
 
Introduction to oracle functions
Nitesh Singh
 
Lecture 8 DML3 aggregate functions in DB.pptx
imranahmadrana28
 
MS Sql Server: Doing Calculations With Functions
DataminingTools Inc
 
MS SQLSERVER:Doing Calculations With Functions
sqlserver content
 
MS SQL SERVER: Doing Calculations With Functions
sqlserver content
 
database_set_operations_&_function.pptx
tanvirkhanfahim
 
Sql FUNCTIONS
Abrar ali
 
Sql group functions
Vivek Singh
 
sql function(ppt)
Ankit Dubey
 
Sql functions
ilias ahmed
 
MySQL-commands.pdf
ssuserc5aa74
 
DBMS: Week 07 - Advanced SQL Queries in MySQL
RashidFaridChishti
 
Sql wksht-3
Mukesh Tekwani
 
Ad

Recently uploaded (20)

PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PDF
Workbook de Inglés Completo - English Path.pdf
shityouenglishpath
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
WATERSHED MANAGEMENT CASE STUDIES - ULUGURU MOUNTAINS AND ARVARI RIVERpdf
Ar.Asna
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Horarios de distribución de agua en julio
pegazohn1978
 
Controller Request and Response in Odoo18
Celine George
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Introduction presentation of the patentbutler tool
MIPLM
 
Workbook de Inglés Completo - English Path.pdf
shityouenglishpath
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
infertility, types,causes, impact, and management
Ritu480198
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
WATERSHED MANAGEMENT CASE STUDIES - ULUGURU MOUNTAINS AND ARVARI RIVERpdf
Ar.Asna
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Introduction to Indian Writing in English
Trushali Dodiya
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 

Aggregate Function - Database

  • 1. Welcome to my Presentation Name: Shahadat Hossain Id: 133-15-3031 Topic: Aggregate Functions [email protected]
  • 2. Aggregate Function: Aggregate functions are functions that take a collection of values as input and return a single value.  Behavior of Aggregate Functions: Operates - on a single column Return - a single value. Used only in the SELECT list and in the HAVING clause.
  • 3. Types of SQL Aggregate Functions: Aggregate Functions: Max() Min() Avg() Sum()
  • 4. Input to Aggregate Function • SUM and AVG :  Operates only on collections of numbers . • MIN , MAX and COUNT  Operates on collection of numeric and non-numeric data types. Each function eliminates NULL values and operates on Non- null values.
  • 5. USE OF SUM() Returns: The sum of the values in a specified column. Example: Find the total/sum of the Managers salary Query: SELECT SUM( salary) AS sum_salary FROM Staff WHERE Staff.position = ‘Manager’; Result: sum_salary 54000.00
  • 6. USE OF AVG() Returns: The average of the values in a specified column. Example: Find the average of the Project Managers salary . Query: SELECT AVG(ALL salary) AS avg_salary FROM Staff WHERE Staff.position = ‘Project Manager’; Result : avg_salary 11000.00
  • 7. Staff sno fname lname salary position SL100 John White 30000.00 Manager SL101 Susan Brand 24000.00 Manager SL102 David Ford 12000.00 Project Manager SL103 Ann Beech 12000.00 Project Manager SL104 Mary Howe 9000.00 Project Manager
  • 8. MIN() and MAX() Returns: MIN() returns the smallest value of a column. MAX() returns the largest value of a column. Example: Find the minimum and maximum staff salary. Query: SELECT MIN( salary) AS min_salary, MAX (salary) AS max_salary FROM Staff; Result: min_salary max_salary 9000.00 30000.00
  • 9. USE OF COUNT() Returns: The number of values in the specified column. Example: Count number of staffs who are Manager. Query: SELECT COUNT(sno) AS sno_count FROM Staff WHERE Staff.position = ‘Manager’; Result: sno_count 2
  • 10. Use of COUNT() and SUM() Example: Find the total number of Managers and the sum of there salary. Query: SELECT COUNT( sno) AS sno_count , SUM(salary) AS sum_salary From Staff WHERE Staff.position = ‘Manager’; sno fname lname salary position SL100 John White 30000.00 Manager SL101 Susan Brand 24000.00 Manager SUMCOUNT
  • 11. COUNT() and SUM() continued • Result: sno_count sum_salary 2 54000.00