SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

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
uncleRhyme
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
Kumar
 
Insertion into linked lists
Insertion into linked lists Insertion into linked lists
Insertion into linked lists
MrDavinderSingh
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
student
 
Linked list
Linked listLinked list
Linked list
VONI
 

Tendances (19)

Linked list
Linked listLinked list
Linked list
 
Unit 3 stack
Unit 3   stackUnit 3   stack
Unit 3 stack
 
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
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
 
linked list
linked list linked list
linked list
 
Sql cheat-sheet
Sql cheat-sheetSql cheat-sheet
Sql cheat-sheet
 
linked list using c
linked list using clinked list using c
linked list using c
 
Address calculation-sort
Address calculation-sortAddress calculation-sort
Address calculation-sort
 
Linked list implementation of Stack
Linked list implementation of StackLinked list implementation of Stack
Linked list implementation of Stack
 
single linked list
single linked listsingle linked list
single linked list
 
Insertion into linked lists
Insertion into linked lists Insertion into linked lists
Insertion into linked lists
 
Insertion operation in array(ds)
Insertion operation in array(ds)Insertion operation in array(ds)
Insertion operation in array(ds)
 
Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
 
Getting started - Warewolf Syntax
Getting started - Warewolf Syntax  Getting started - Warewolf Syntax
Getting started - Warewolf Syntax
 
Data Structure (Stack)
Data Structure (Stack)Data Structure (Stack)
Data Structure (Stack)
 
Linked list
Linked listLinked list
Linked list
 
Linklist
LinklistLinklist
Linklist
 
Linked list
Linked listLinked list
Linked list
 

En vedette (15)

Introduction to oracle
Introduction to oracleIntroduction to oracle
Introduction to oracle
 
Virtualization strategies
Virtualization strategiesVirtualization strategies
Virtualization strategies
 
2123.a better waytoprint.universal print
2123.a better waytoprint.universal print2123.a better waytoprint.universal print
2123.a better waytoprint.universal print
 
Ch1 2
Ch1 2Ch1 2
Ch1 2
 
Advanced dreamweaver
Advanced dreamweaverAdvanced dreamweaver
Advanced dreamweaver
 
Ch05
Ch05Ch05
Ch05
 
Jcc
JccJcc
Jcc
 
Ccna2v3 mod07
Ccna2v3 mod07Ccna2v3 mod07
Ccna2v3 mod07
 
Birthday greeting 2009
Birthday greeting 2009Birthday greeting 2009
Birthday greeting 2009
 
12.ibm r50 ibm wireless setup
12.ibm r50 ibm wireless setup12.ibm r50 ibm wireless setup
12.ibm r50 ibm wireless setup
 
Advanced dreamweaver
Advanced dreamweaverAdvanced dreamweaver
Advanced dreamweaver
 
Ms dos
Ms dosMs dos
Ms dos
 
Cos413day3
Cos413day3Cos413day3
Cos413day3
 
Notes server setup
Notes server setupNotes server setup
Notes server setup
 
Java tut1
Java tut1Java tut1
Java tut1
 

Similaire à Sql group functions(2)

Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
paulguerin
 
Key functions in_oracle_sql
Key functions in_oracle_sqlKey functions in_oracle_sql
Key functions in_oracle_sql
pgolhar
 
Sydney Oracle Meetup - indexes
Sydney Oracle Meetup - indexesSydney Oracle Meetup - indexes
Sydney Oracle Meetup - indexes
paulguerin
 
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
MohammedJifar1
 
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
todd331
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracle
Logan Palanisamy
 

Similaire à Sql group functions(2) (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
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracle
 
Data structures using C
Data structures using CData structures using C
Data structures using C
 

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