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

What's hot (19)

PPT
Linked list
eShikshak
 
PPT
Unit 3 stack
kalyanineve
 
PPTX
02 database oprimization - improving sql performance - ent-db
uncleRhyme
 
PPT
Data structure lecture 5
Kumar
 
PPT
linked list
Narendra Chauhan
 
PDF
Sql cheat-sheet
Steve Tran
 
PPTX
linked list using c
Venkat Reddy
 
PPTX
Address calculation-sort
Vasim Pathan
 
PDF
Linked list implementation of Stack
Dr. Sindhia Lingaswamy
 
PPTX
single linked list
Sathasivam Rangasamy
 
PPTX
Insertion into linked lists
MrDavinderSingh
 
PPTX
Insertion operation in array(ds)
chauhankapil
 
PPTX
Link list presentation slide(Daffodil international university)
shah alom
 
PPT
header, circular and two way linked lists
student
 
PPTX
Getting started - Warewolf Syntax
Carol Vanden Bussche
 
PPSX
Data Structure (Stack)
Adam Mukharil Bachtiar
 
PPTX
Linked list
VONI
 
PPTX
Linklist
SHEETAL WAGHMARE
 
PPTX
Linked list
akshat360
 
Linked list
eShikshak
 
Unit 3 stack
kalyanineve
 
02 database oprimization - improving sql performance - ent-db
uncleRhyme
 
Data structure lecture 5
Kumar
 
linked list
Narendra Chauhan
 
Sql cheat-sheet
Steve Tran
 
linked list using c
Venkat Reddy
 
Address calculation-sort
Vasim Pathan
 
Linked list implementation of Stack
Dr. Sindhia Lingaswamy
 
single linked list
Sathasivam Rangasamy
 
Insertion into linked lists
MrDavinderSingh
 
Insertion operation in array(ds)
chauhankapil
 
Link list presentation slide(Daffodil international university)
shah alom
 
header, circular and two way linked lists
student
 
Getting started - Warewolf Syntax
Carol Vanden Bussche
 
Data Structure (Stack)
Adam Mukharil Bachtiar
 
Linked list
VONI
 
Linked list
akshat360
 

Viewers also liked (15)

PPT
Introduction to oracle
Sumit Tambe
 
PPT
Virtualization strategies
Sumit Tambe
 
PPT
2123.a better waytoprint.universal print
Sumit Tambe
 
PPT
Ch1 2
Sumit Tambe
 
PDF
Advanced dreamweaver
Sumit Tambe
 
PPT
Ch05
Sumit Tambe
 
PPT
Jcc
Sumit Tambe
 
PPT
Ccna2v3 mod07
Sumit Tambe
 
PPT
Birthday greeting 2009
Sumit Tambe
 
PDF
12.ibm r50 ibm wireless setup
Sumit Tambe
 
PPT
Advanced dreamweaver
Sumit Tambe
 
PPT
Ms dos
Sumit Tambe
 
PPT
Cos413day3
Sumit Tambe
 
PPT
Notes server setup
Sumit Tambe
 
PPT
Java tut1
Sumit Tambe
 
Introduction to oracle
Sumit Tambe
 
Virtualization strategies
Sumit Tambe
 
2123.a better waytoprint.universal print
Sumit Tambe
 
Advanced dreamweaver
Sumit Tambe
 
Ccna2v3 mod07
Sumit Tambe
 
Birthday greeting 2009
Sumit Tambe
 
12.ibm r50 ibm wireless setup
Sumit Tambe
 
Advanced dreamweaver
Sumit Tambe
 
Ms dos
Sumit Tambe
 
Cos413day3
Sumit Tambe
 
Notes server setup
Sumit Tambe
 
Java tut1
Sumit Tambe
 
Ad

Similar to Sql group functions(2) (20)

PDF
Oracle Advanced SQL and Analytic Functions
Zohar Elkayam
 
PDF
OOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
Zohar Elkayam
 
PPTX
Pandas csv
Devashish Kumar
 
PDF
Lecture 5- group function.pdf
shanonechlo
 
PPTX
Exploring Advanced SQL Techniques Using Analytic Functions
Zohar Elkayam
 
PPTX
Exploring Advanced SQL Techniques Using Analytic Functions
Zohar Elkayam
 
PDF
SQL Functions - Oracle SQL Fundamentals
MuhammadWaheed44
 
PPT
INTRODUCTION TO SQL QUERIES REALTED BRIEF
VADAPALLYPRAVEENKUMA1
 
PPT
2 sql - single-row functions
Ankit Dubey
 
PDF
5. Group Functions
Evelyn Oluchukwu
 
PPT
Myth busters - performance tuning 101 2007
paulguerin
 
ODP
Mysqlppt
poornima sugumaran
 
ODP
Mysqlppt
poornima sugumaran
 
PDF
Key functions in_oracle_sql
pgolhar
 
PPTX
New T-SQL Features in SQL Server 2012
Richie Rump
 
PPT
Sydney Oracle Meetup - indexes
paulguerin
 
PPT
Using SQL Queries to Insert, Update, Delete, and View Data.ppt
MohammedJifar1
 
PPT
chapter03.ppt
NalamalpuBhakthavats
 
DOCX
Sample Questions The following sample questions are not in.docx
todd331
 
PPTX
python series and dataframe of pandas data structures
daffodils0208
 
Oracle Advanced SQL and Analytic Functions
Zohar Elkayam
 
OOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
Zohar Elkayam
 
Pandas csv
Devashish Kumar
 
Lecture 5- group function.pdf
shanonechlo
 
Exploring Advanced SQL Techniques Using Analytic Functions
Zohar Elkayam
 
Exploring Advanced SQL Techniques Using Analytic Functions
Zohar Elkayam
 
SQL Functions - Oracle SQL Fundamentals
MuhammadWaheed44
 
INTRODUCTION TO SQL QUERIES REALTED BRIEF
VADAPALLYPRAVEENKUMA1
 
2 sql - single-row functions
Ankit Dubey
 
5. Group Functions
Evelyn Oluchukwu
 
Myth busters - performance tuning 101 2007
paulguerin
 
Key functions in_oracle_sql
pgolhar
 
New T-SQL Features in SQL Server 2012
Richie Rump
 
Sydney Oracle Meetup - indexes
paulguerin
 
Using SQL Queries to Insert, Update, Delete, and View Data.ppt
MohammedJifar1
 
chapter03.ppt
NalamalpuBhakthavats
 
Sample Questions The following sample questions are not in.docx
todd331
 
python series and dataframe of pandas data structures
daffodils0208
 
Ad

Sql group functions(2)

  • 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