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

PPT
Aggregate functions
PPTX
SQL JOIN
PPT
SQL subquery
PPT
SQL Views
PPTX
SQL Joins.pptx
PPTX
SQL commands
PPTX
Group By, Having Clause and Order By clause
Aggregate functions
SQL JOIN
SQL subquery
SQL Views
SQL Joins.pptx
SQL commands
Group By, Having Clause and Order By clause

What's hot (20)

PPT
SQL select statement and functions
PPT
Mysql
PPT
Including Constraints -Oracle Data base
PDF
Normalization in DBMS
PPTX
Sql joins inner join self join outer joins
PPTX
SQL - DML and DDL Commands
PPT
ADO .Net
PPTX
Aggregate function
PPTX
PPTX
Stored procedure in sql server
PPTX
Normalization in DBMS
PPTX
Key and its different types
PPTX
Architecture of dbms(lecture 3)
PPTX
Stored procedures
PPTX
Packages in PL/SQL
PPT
Introduction to structured query language (sql)
PDF
PPT
Database Triggers
PPTX
Chapter 1 introduction to sql server
PPTX
database language ppt.pptx
SQL select statement and functions
Mysql
Including Constraints -Oracle Data base
Normalization in DBMS
Sql joins inner join self join outer joins
SQL - DML and DDL Commands
ADO .Net
Aggregate function
Stored procedure in sql server
Normalization in DBMS
Key and its different types
Architecture of dbms(lecture 3)
Stored procedures
Packages in PL/SQL
Introduction to structured query language (sql)
Database Triggers
Chapter 1 introduction to sql server
database language ppt.pptx
Ad

Viewers also liked (20)

PPT
PHP mysql Aggregate functions
PPT
Aggregate Functions,Final
PPT
Aggregating Data Using Group Functions
PPTX
Sql Basics And Advanced
PDF
Agreggates i
PPT
PPTX
Cellular Telephone Networks 2008
PDF
namecard
 
PDF
7 relational database design algorithms and further dependencies
PPTX
Cellular Telephone Systems
PPT
Unit05 dbms
PPT
Relational Algebra
PPTX
New Perspectives: Access.03
PPT
Relational Algebra-Database Systems
PPTX
DOC
SQL Joins
PPTX
Sql joins
PPT
functional dependencies with example
PDF
Basic structures in vhdl
PHP mysql Aggregate functions
Aggregate Functions,Final
Aggregating Data Using Group Functions
Sql Basics And Advanced
Agreggates i
Cellular Telephone Networks 2008
namecard
 
7 relational database design algorithms and further dependencies
Cellular Telephone Systems
Unit05 dbms
Relational Algebra
New Perspectives: Access.03
Relational Algebra-Database Systems
SQL Joins
Sql joins
functional dependencies with example
Basic structures in vhdl
Ad

Similar to Aggregate Function - Database (20)

PPTX
AGGREGATE FUNCTION.pptx
PPTX
aggregatefunction-220420051702.pptx aggregate
PDF
SQL-AGG-FUN.pdfiiiijuyyttfffgyyuyyyyyhhh
PPTX
SQL.pptx
PPT
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
DOCX
Database Query Using SQL_ip.docx
PPTX
V22 function-1
PDF
Introduction to oracle functions
PPTX
Lecture 8 DML3 aggregate functions in DB.pptx
PPTX
MS Sql Server: Doing Calculations With Functions
PPTX
MS SQLSERVER:Doing Calculations With Functions
PPTX
MS SQL SERVER: Doing Calculations With Functions
PPTX
database_set_operations_&_function.pptx
PPTX
Sql FUNCTIONS
PDF
Sql group functions
PPTX
sql function(ppt)
RTF
Sql functions
PDF
MySQL-commands.pdf
PPTX
DBMS: Week 07 - Advanced SQL Queries in MySQL
PDF
Sql wksht-3
AGGREGATE FUNCTION.pptx
aggregatefunction-220420051702.pptx aggregate
SQL-AGG-FUN.pdfiiiijuyyttfffgyyuyyyyyhhh
SQL.pptx
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Database Query Using SQL_ip.docx
V22 function-1
Introduction to oracle functions
Lecture 8 DML3 aggregate functions in DB.pptx
MS Sql Server: Doing Calculations With Functions
MS SQLSERVER:Doing Calculations With Functions
MS SQL SERVER: Doing Calculations With Functions
database_set_operations_&_function.pptx
Sql FUNCTIONS
Sql group functions
sql function(ppt)
Sql functions
MySQL-commands.pdf
DBMS: Week 07 - Advanced SQL Queries in MySQL
Sql wksht-3

Recently uploaded (20)

PDF
Insiders guide to clinical Medicine.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Lesson notes of climatology university.
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Basic Mud Logging Guide for educational purpose
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
TR - Agricultural Crops Production NC III.pdf
Insiders guide to clinical Medicine.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
01-Introduction-to-Information-Management.pdf
Microbial diseases, their pathogenesis and prophylaxis
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Lesson notes of climatology university.
PPH.pptx obstetrics and gynecology in nursing
O5-L3 Freight Transport Ops (International) V1.pdf
Supply Chain Operations Speaking Notes -ICLT Program
VCE English Exam - Section C Student Revision Booklet
Basic Mud Logging Guide for educational purpose
Anesthesia in Laparoscopic Surgery in India
human mycosis Human fungal infections are called human mycosis..pptx
Complications of Minimal Access Surgery at WLH
Pharmacology of Heart Failure /Pharmacotherapy of CHF
TR - Agricultural Crops Production NC III.pdf

Aggregate Function - Database

  • 1. Welcome to my Presentation Name: Shahadat Hossain Id: 133-15-3031 Topic: Aggregate Functions shahadat3031@gmail.com
  • 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