SlideShare a Scribd company logo
1 of 20
Introduction to 1
SQL Group Functions
Introduction to 2
Chapter Objectives
• Differentiate between single-row and multiple-row
functions
• Use the SUM and AVG functions for numeric
calculations
• Use the COUNT function to return the number of
records containing non-NULL values
• Use COUNT(*) to include records containing
NULL values
Introduction to 3
Chapter Objectives
• Use the MIN and MAX functions with non-
numeric fields
• Determine when to use the GROUP BY
clause to group data
• Identify when the HAVING clause should
be used
• List the order of precedence for evaluating
WHERE, GROUP BY, and HAVING
clauses
Introduction to 4
Chapter Objectives
• State the maximum depth for nesting group
functions
• Nest a group function inside a single-row
function
• Calculate the standard deviation and
variance of a set of data, using the
STDDEV and VARIANCE functions
Introduction to 5
Group Functions
• Return one result per group of rows
processed
• Also called multiple-row and aggregate
functions
• All group functions ignore NULL values
except COUNT(*)
• Use DISTINCT to suppress duplicate
values
Introduction to 6
SUM Function
Calculates total amount stored in a numeric
column for a group of rows
Introduction to 7
AVG Function
Calculates average of numeric values in a
specified column
Introduction to 8
COUNT Function
Two purposes:
– Count non-NULL values
– Count total records, including those with NULL
values
Introduction to 9
COUNT Function –
Non-NULL Values
Include column name in argument to count
number of occurrences
Introduction to 10
COUNT Function –
NULL Values
Include asterisk in argument to count
number of rows
Introduction to 11
MAX Function
Returns largest value
Introduction to 12
MIN Function
Returns smallest value
Introduction to 13
GROUP BY Clause
• Used to group data
• Must be used for individual column in the
SELECT clause with a group function
• Cannot reference column alias
Introduction to 14
GROUP BY Example
Introduction to 15
HAVING Clause//
Serves as the WHERE clause for grouped
data
Introduction to 16
Order of Clause Evaluation
When included in the same SELECT
statement, evaluated in order of:
– WHERE
– GROUP BY
– HAVING
Introduction to 17
Nesting Functions
• Inner function resolved first
• Maximum nesting depth: 2
Introduction to 18
Statistical Group Functions
• Based on normal distribution
• Includes:
– STDDEV
– VARIANCE
Introduction to 19
STDDEV Function
Calculates standard deviation for grouped
data
Introduction to 20
VARIANCE Function
Determines data dispersion within a group

More Related Content

What's hot (20)

AGGREGATE FUNCTION.pptx
AGGREGATE FUNCTION.pptxAGGREGATE FUNCTION.pptx
AGGREGATE FUNCTION.pptx
 
SQL BASIC QUERIES SOLUTION ~hmftj
SQL BASIC QUERIES SOLUTION ~hmftjSQL BASIC QUERIES SOLUTION ~hmftj
SQL BASIC QUERIES SOLUTION ~hmftj
 
Complex queries in sql
Complex queries in sqlComplex queries in sql
Complex queries in sql
 
Aggregate function
Aggregate functionAggregate function
Aggregate function
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
80 different SQL Queries with output
80 different SQL Queries with output80 different SQL Queries with output
80 different SQL Queries with output
 
Sql commands
Sql commandsSql commands
Sql commands
 
Sql operator
Sql operatorSql operator
Sql operator
 
Sql joins
Sql joinsSql joins
Sql joins
 
Sql Tutorials
Sql TutorialsSql Tutorials
Sql Tutorials
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
Sql and Sql commands
Sql and Sql commandsSql and Sql commands
Sql and Sql commands
 
Advanced sql
Advanced sqlAdvanced sql
Advanced sql
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
Database Objects
Database ObjectsDatabase Objects
Database Objects
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
Aggregating Data Using Group Functions
Aggregating Data Using Group FunctionsAggregating Data Using Group Functions
Aggregating Data Using Group Functions
 
SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
 

Viewers also liked

Профилирование памяти в приложениях на Python, Антон Грицай
Профилирование памяти в приложениях на Python, Антон ГрицайПрофилирование памяти в приложениях на Python, Антон Грицай
Профилирование памяти в приложениях на Python, Антон ГрицайFuenteovejuna
 
Сервер-агрегатор на python (аля Xscript FEST), Сумин Андрей, Сабуренков Михаи...
Сервер-агрегатор на python (аля Xscript FEST), Сумин Андрей, Сабуренков Михаи...Сервер-агрегатор на python (аля Xscript FEST), Сумин Андрей, Сабуренков Михаи...
Сервер-агрегатор на python (аля Xscript FEST), Сумин Андрей, Сабуренков Михаи...Fuenteovejuna
 
Facebook, Robert Johnson
Facebook, Robert JohnsonFacebook, Robert Johnson
Facebook, Robert JohnsonFuenteovejuna
 
Динамика DDoS-атак в России, Александр Лямин
Динамика DDoS-атак в России, Александр ЛяминДинамика DDoS-атак в России, Александр Лямин
Динамика DDoS-атак в России, Александр ЛяминFuenteovejuna
 
Shared Personalization Service - How To Scale to 15K RPS, Patrice Pelland
Shared Personalization Service - How To Scale to 15K RPS, Patrice PellandShared Personalization Service - How To Scale to 15K RPS, Patrice Pelland
Shared Personalization Service - How To Scale to 15K RPS, Patrice PellandFuenteovejuna
 
Goal Driven Performance Optimization, Peter Zaitsev
Goal Driven Performance Optimization, Peter ZaitsevGoal Driven Performance Optimization, Peter Zaitsev
Goal Driven Performance Optimization, Peter ZaitsevFuenteovejuna
 
Extreme Cloud Storage on FreeBSD, Андрей Пантюхин
Extreme Cloud Storage on FreeBSD, Андрей ПантюхинExtreme Cloud Storage on FreeBSD, Андрей Пантюхин
Extreme Cloud Storage on FreeBSD, Андрей ПантюхинFuenteovejuna
 

Viewers also liked (7)

Профилирование памяти в приложениях на Python, Антон Грицай
Профилирование памяти в приложениях на Python, Антон ГрицайПрофилирование памяти в приложениях на Python, Антон Грицай
Профилирование памяти в приложениях на Python, Антон Грицай
 
Сервер-агрегатор на python (аля Xscript FEST), Сумин Андрей, Сабуренков Михаи...
Сервер-агрегатор на python (аля Xscript FEST), Сумин Андрей, Сабуренков Михаи...Сервер-агрегатор на python (аля Xscript FEST), Сумин Андрей, Сабуренков Михаи...
Сервер-агрегатор на python (аля Xscript FEST), Сумин Андрей, Сабуренков Михаи...
 
Facebook, Robert Johnson
Facebook, Robert JohnsonFacebook, Robert Johnson
Facebook, Robert Johnson
 
Динамика DDoS-атак в России, Александр Лямин
Динамика DDoS-атак в России, Александр ЛяминДинамика DDoS-атак в России, Александр Лямин
Динамика DDoS-атак в России, Александр Лямин
 
Shared Personalization Service - How To Scale to 15K RPS, Patrice Pelland
Shared Personalization Service - How To Scale to 15K RPS, Patrice PellandShared Personalization Service - How To Scale to 15K RPS, Patrice Pelland
Shared Personalization Service - How To Scale to 15K RPS, Patrice Pelland
 
Goal Driven Performance Optimization, Peter Zaitsev
Goal Driven Performance Optimization, Peter ZaitsevGoal Driven Performance Optimization, Peter Zaitsev
Goal Driven Performance Optimization, Peter Zaitsev
 
Extreme Cloud Storage on FreeBSD, Андрей Пантюхин
Extreme Cloud Storage on FreeBSD, Андрей ПантюхинExtreme Cloud Storage on FreeBSD, Андрей Пантюхин
Extreme Cloud Storage on FreeBSD, Андрей Пантюхин
 

Similar to Sql group functions

Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsZohar Elkayam
 
OOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
OOW2016: Exploring Advanced SQL Techniques Using Analytic FunctionsOOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
OOW2016: Exploring Advanced SQL Techniques Using Analytic FunctionsZohar Elkayam
 
Lecture 5- group function.pdf
Lecture 5- group function.pdfLecture 5- group function.pdf
Lecture 5- group function.pdfshanonechlo
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsZohar Elkayam
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsZohar Elkayam
 
SQL Functions - Oracle SQL Fundamentals
SQL Functions - Oracle SQL FundamentalsSQL Functions - Oracle SQL Fundamentals
SQL Functions - Oracle SQL FundamentalsMuhammadWaheed44
 
2 sql - single-row functions
2   sql - single-row functions2   sql - single-row functions
2 sql - single-row functionsAnkit Dubey
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007paulguerin
 
Key functions in_oracle_sql
Key functions in_oracle_sqlKey functions in_oracle_sql
Key functions in_oracle_sqlpgolhar
 
New T-SQL Features in SQL Server 2012
New T-SQL Features in SQL Server 2012 New T-SQL Features in SQL Server 2012
New T-SQL Features in SQL Server 2012 Richie Rump
 
Sydney Oracle Meetup - indexes
Sydney Oracle Meetup - indexesSydney Oracle Meetup - indexes
Sydney Oracle Meetup - indexespaulguerin
 
Using SQL Queries to Insert, Update, Delete, and View Data.ppt
Using SQL Queries to Insert, Update, Delete, and View Data.pptUsing SQL Queries to Insert, Update, Delete, and View Data.ppt
Using SQL Queries to Insert, Update, Delete, and View Data.pptMohammedJifar1
 
Sample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docxSample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docxtodd331
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-dbuncleRhyme
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracleLogan Palanisamy
 

Similar to Sql group functions (20)

Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic Functions
 
OOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
OOW2016: Exploring Advanced SQL Techniques Using Analytic FunctionsOOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
OOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
 
Pandas csv
Pandas csvPandas csv
Pandas csv
 
Lecture 5- group function.pdf
Lecture 5- group function.pdfLecture 5- group function.pdf
Lecture 5- group function.pdf
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic Functions
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic Functions
 
SQL Functions - Oracle SQL Fundamentals
SQL Functions - Oracle SQL FundamentalsSQL Functions - Oracle SQL Fundamentals
SQL Functions - Oracle SQL Fundamentals
 
2 sql - single-row functions
2   sql - single-row functions2   sql - single-row functions
2 sql - single-row functions
 
5. Group Functions
5. Group Functions5. Group Functions
5. Group Functions
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Key functions in_oracle_sql
Key functions in_oracle_sqlKey functions in_oracle_sql
Key functions in_oracle_sql
 
New T-SQL Features in SQL Server 2012
New T-SQL Features in SQL Server 2012 New T-SQL Features in SQL Server 2012
New T-SQL Features in SQL Server 2012
 
Sydney Oracle Meetup - indexes
Sydney Oracle Meetup - indexesSydney Oracle Meetup - indexes
Sydney Oracle Meetup - indexes
 
chapter03.ppt
chapter03.pptchapter03.ppt
chapter03.ppt
 
Using SQL Queries to Insert, Update, Delete, and View Data.ppt
Using SQL Queries to Insert, Update, Delete, and View Data.pptUsing SQL Queries to Insert, Update, Delete, and View Data.ppt
Using SQL Queries to Insert, Update, Delete, and View Data.ppt
 
Sample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docxSample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docx
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracle
 

Sql group functions

  • 1. Introduction to 1 SQL Group Functions
  • 2. Introduction to 2 Chapter Objectives • Differentiate between single-row and multiple-row functions • Use the SUM and AVG functions for numeric calculations • Use the COUNT function to return the number of records containing non-NULL values • Use COUNT(*) to include records containing NULL values
  • 3. Introduction to 3 Chapter Objectives • Use the MIN and MAX functions with non- numeric fields • Determine when to use the GROUP BY clause to group data • Identify when the HAVING clause should be used • List the order of precedence for evaluating WHERE, GROUP BY, and HAVING clauses
  • 4. Introduction to 4 Chapter Objectives • State the maximum depth for nesting group functions • Nest a group function inside a single-row function • Calculate the standard deviation and variance of a set of data, using the STDDEV and VARIANCE functions
  • 5. Introduction to 5 Group Functions • Return one result per group of rows processed • Also called multiple-row and aggregate functions • All group functions ignore NULL values except COUNT(*) • Use DISTINCT to suppress duplicate values
  • 6. Introduction to 6 SUM Function Calculates total amount stored in a numeric column for a group of rows
  • 7. Introduction to 7 AVG Function Calculates average of numeric values in a specified column
  • 8. Introduction to 8 COUNT Function Two purposes: – Count non-NULL values – Count total records, including those with NULL values
  • 9. Introduction to 9 COUNT Function – Non-NULL Values Include column name in argument to count number of occurrences
  • 10. Introduction to 10 COUNT Function – NULL Values Include asterisk in argument to count number of rows
  • 11. Introduction to 11 MAX Function Returns largest value
  • 12. Introduction to 12 MIN Function Returns smallest value
  • 13. Introduction to 13 GROUP BY Clause • Used to group data • Must be used for individual column in the SELECT clause with a group function • Cannot reference column alias
  • 15. Introduction to 15 HAVING Clause// Serves as the WHERE clause for grouped data
  • 16. Introduction to 16 Order of Clause Evaluation When included in the same SELECT statement, evaluated in order of: – WHERE – GROUP BY – HAVING
  • 17. Introduction to 17 Nesting Functions • Inner function resolved first • Maximum nesting depth: 2
  • 18. Introduction to 18 Statistical Group Functions • Based on normal distribution • Includes: – STDDEV – VARIANCE
  • 19. Introduction to 19 STDDEV Function Calculates standard deviation for grouped data
  • 20. Introduction to 20 VARIANCE Function Determines data dispersion within a group