SlideShare a Scribd company logo
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

PPT
Sql operators & functions 3
PPT
Aggregating Data Using Group Functions
PPT
1 - Introduction to PL/SQL
PPTX
Sql operator
PDF
5. Group Functions
PPT
Single row functions
PDF
Oracle Advanced SQL and Analytic Functions
PPTX
Sql and Sql commands
Sql operators & functions 3
Aggregating Data Using Group Functions
1 - Introduction to PL/SQL
Sql operator
5. Group Functions
Single row functions
Oracle Advanced SQL and Analytic Functions
Sql and Sql commands

What's hot (20)

PPTX
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
PDF
Exception Handling
PPTX
PLSQL Tutorial
PDF
View & index in SQL
PPTX
SQL commands
PPT
Including Constraints -Oracle Data base
PPTX
SQL - DML and DDL Commands
PPTX
4. plsql
PPTX
SQL Functions
PPTX
Packages in PL/SQL
PPTX
Nested queries in database
PPT
Aggregate functions
PDF
Sql commands
PDF
Sql functions
PPTX
Unit 9. Structure and Unions
PPT
PL/SQL Introduction and Concepts
PPT
SQL subquery
PPTX
Structured Query Language (SQL)
PDF
Assignment#02
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
Exception Handling
PLSQL Tutorial
View & index in SQL
SQL commands
Including Constraints -Oracle Data base
SQL - DML and DDL Commands
4. plsql
SQL Functions
Packages in PL/SQL
Nested queries in database
Aggregate functions
Sql commands
Sql functions
Unit 9. Structure and Unions
PL/SQL Introduction and Concepts
SQL subquery
Structured Query Language (SQL)
Assignment#02
Ad

Viewers also liked (7)

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

Similar to Sql group functions (20)

PDF
Writing Group Functions - DBMS
PPT
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
PDF
Sql wksht-3
PDF
Introduction to oracle functions
PPT
PPT
PDF
SQL-AGG-FUN.pdfiiiijuyyttfffgyyuyyyyyhhh
PPT
Aggregate Functions,Final
PPT
PDF
Consultas con agrupaci¾n de datos
PPTX
MYSQL GROUP FUNCTION.pptx
PPT
Les04- Reporting Aggregated Data Using the Group Functions.ppt
DOCX
Database Query Using SQL_ip.docx
PPTX
Unit 5 Introduction to Oracle and Sql.pptx
PDF
Sql group functions
PPTX
Unit 3-Select Options and Aggregate Functions in SQL (1).pptx
PDF
Lecture 5- group function.pdf
RTF
Sql functions
PPTX
Aggregate Function - Database
PPTX
Aggregating data
Writing Group Functions - DBMS
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Sql wksht-3
Introduction to oracle functions
SQL-AGG-FUN.pdfiiiijuyyttfffgyyuyyyyyhhh
Aggregate Functions,Final
Consultas con agrupaci¾n de datos
MYSQL GROUP FUNCTION.pptx
Les04- Reporting Aggregated Data Using the Group Functions.ppt
Database Query Using SQL_ip.docx
Unit 5 Introduction to Oracle and Sql.pptx
Sql group functions
Unit 3-Select Options and Aggregate Functions in SQL (1).pptx
Lecture 5- group function.pdf
Sql functions
Aggregate Function - Database
Aggregating data

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