SlideShare a Scribd company logo
Presented by Aaron Buma
Agenda
 COUNT(), SUM(), MIN(), MAX(), AVG()
 Accounting for NULLs
 Grouping on multiple fields
 Ordering Results
 HAVING – Filtering on Aggregate fields
 Filtering on Aggregate and non-aggregate fields
 DISTINCT
COUNT(), SUM(), MIN(), MAX(), AVG()
 function(expression) – Expressions generally column name
 COUNT(x) – number of matching records, can be *, 1,
column
 SUM(x) – summation of expression or column per group
 MIN(x) – minimum of expression value per group
 MAX(x) – maximum of expression value per group
 AVG(x) – average of expression value per group
Aggregation Details
 Accounting for NULLs
 Grouping on Multiple Fields
 ORDER BY on Aggregate Fields
HAVING - Filtering on Aggregate Fields
 The ‘HAVING’ clause
 Including non-Aggregate field in filtering
DISTINCT - Filtering on Aggregate Fields
 The ‘DISTINCT’ clause
 How to include with COUNT(), MIN(), MAX(), AVG()
 Does it account for NULLS?
Question 1
SELECT DateRecorded,
VoteID,
COUNT(User) AS [Count]
FROM VoterTable
GROUP BY DateRecord,
VoteID;
Question 2
 Total Cost of inventory on hand?
Question 2
Any Questions?
 COUNT(), SUM(), MIN(), MAX(), AVG()
 Accounting for NULLs
 Grouping on multiple fields
 Ordering Results
 HAVING – Filtering on Aggregate fields
 Filtering on Aggregate and non-aggregate fields
 DISTINCT

More Related Content

What's hot

Workstructure erd
Workstructure erdWorkstructure erd
Workstructure erd
sks6184
 
Multiquery optimization on spark
Multiquery optimization on sparkMultiquery optimization on spark
Multiquery optimization on spark
Bự Bụng
 
as400 built in function- %SIZE
as400 built in function- %SIZEas400 built in function- %SIZE
as400 built in function- %SIZE
aminem_mp
 
C# example (Polymorphesim)
C# example (Polymorphesim)C# example (Polymorphesim)
C# example (Polymorphesim)
MaRwa Samih AL-Amri
 
Symmetry in the interrelation of flatMap/foldMap/traverse and flatten/fold/se...
Symmetry in the interrelation of flatMap/foldMap/traverse and flatten/fold/se...Symmetry in the interrelation of flatMap/foldMap/traverse and flatten/fold/se...
Symmetry in the interrelation of flatMap/foldMap/traverse and flatten/fold/se...
Philip Schwarz
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
Golden Julie Jesus
 
Javascript Array map method
Javascript Array map methodJavascript Array map method
Javascript Array map method
tanerochris
 
Basic Calculus in R.
Basic Calculus in R. Basic Calculus in R.
Basic Calculus in R.
Dr. Volkan OBAN
 

What's hot (8)

Workstructure erd
Workstructure erdWorkstructure erd
Workstructure erd
 
Multiquery optimization on spark
Multiquery optimization on sparkMultiquery optimization on spark
Multiquery optimization on spark
 
as400 built in function- %SIZE
as400 built in function- %SIZEas400 built in function- %SIZE
as400 built in function- %SIZE
 
C# example (Polymorphesim)
C# example (Polymorphesim)C# example (Polymorphesim)
C# example (Polymorphesim)
 
Symmetry in the interrelation of flatMap/foldMap/traverse and flatten/fold/se...
Symmetry in the interrelation of flatMap/foldMap/traverse and flatten/fold/se...Symmetry in the interrelation of flatMap/foldMap/traverse and flatten/fold/se...
Symmetry in the interrelation of flatMap/foldMap/traverse and flatten/fold/se...
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Javascript Array map method
Javascript Array map methodJavascript Array map method
Javascript Array map method
 
Basic Calculus in R.
Basic Calculus in R. Basic Calculus in R.
Basic Calculus in R.
 

Viewers also liked

SQL Triggers
SQL TriggersSQL Triggers
SQL Triggers
Aaron Buma
 
Spatial data types
Spatial data typesSpatial data types
Spatial data types
Aaron Buma
 
Digital
DigitalDigital
Home Depot
Home DepotHome Depot
Home Depot
Michael Grob
 
Prezentacija 1
Prezentacija 1Prezentacija 1
Prezentacija 1
flp
 
Connected Health Presentationo May 2016 final
Connected Health Presentationo May 2016 finalConnected Health Presentationo May 2016 final
Connected Health Presentationo May 2016 final
Phillip Thomas
 
XQuery Extensions
XQuery ExtensionsXQuery Extensions
XQuery Extensions
Aaron Buma
 
SQL Server GUIDS (Globally Unique Identifiers)
SQL Server GUIDS (Globally Unique Identifiers)SQL Server GUIDS (Globally Unique Identifiers)
SQL Server GUIDS (Globally Unique Identifiers)
Aaron Buma
 
HIMSS15_TeleHealth Strategy_118Final
HIMSS15_TeleHealth Strategy_118FinalHIMSS15_TeleHealth Strategy_118Final
HIMSS15_TeleHealth Strategy_118FinalJeff Jones
 
російські художники
російські художникиросійські художники
російські художники
Slovyansk School
 
SQL Server - Constraints
SQL Server - ConstraintsSQL Server - Constraints
SQL Server - Constraints
Aaron Buma
 
SQL Views
SQL ViewsSQL Views
SQL Views
Aaron Buma
 
Қаратай Еламан+ Строительная крмпания+ Покупатели
Қаратай Еламан+ Строительная крмпания+ ПокупателиҚаратай Еламан+ Строительная крмпания+ Покупатели
Қаратай Еламан+ Строительная крмпания+ Покупатели
Elaman Karatay
 
Telehealth program additions
Telehealth program additionsTelehealth program additions
Telehealth program additions
FlexCare
 

Viewers also liked (16)

SQL Triggers
SQL TriggersSQL Triggers
SQL Triggers
 
Spatial data types
Spatial data typesSpatial data types
Spatial data types
 
Digital
DigitalDigital
Digital
 
Conjuro
ConjuroConjuro
Conjuro
 
Home Depot
Home DepotHome Depot
Home Depot
 
Prezentacija 1
Prezentacija 1Prezentacija 1
Prezentacija 1
 
Connected Health Presentationo May 2016 final
Connected Health Presentationo May 2016 finalConnected Health Presentationo May 2016 final
Connected Health Presentationo May 2016 final
 
XQuery Extensions
XQuery ExtensionsXQuery Extensions
XQuery Extensions
 
SQL Server GUIDS (Globally Unique Identifiers)
SQL Server GUIDS (Globally Unique Identifiers)SQL Server GUIDS (Globally Unique Identifiers)
SQL Server GUIDS (Globally Unique Identifiers)
 
HIMSS15_TeleHealth Strategy_118Final
HIMSS15_TeleHealth Strategy_118FinalHIMSS15_TeleHealth Strategy_118Final
HIMSS15_TeleHealth Strategy_118Final
 
російські художники
російські художникиросійські художники
російські художники
 
SQL Server - Constraints
SQL Server - ConstraintsSQL Server - Constraints
SQL Server - Constraints
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Қаратай Еламан+ Строительная крмпания+ Покупатели
Қаратай Еламан+ Строительная крмпания+ ПокупателиҚаратай Еламан+ Строительная крмпания+ Покупатели
Қаратай Еламан+ Строительная крмпания+ Покупатели
 
CLIVE KLL
CLIVE KLLCLIVE KLL
CLIVE KLL
 
Telehealth program additions
Telehealth program additionsTelehealth program additions
Telehealth program additions
 

Recently uploaded

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 

Recently uploaded (20)

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 

Aggregating data

  • 2. Agenda  COUNT(), SUM(), MIN(), MAX(), AVG()  Accounting for NULLs  Grouping on multiple fields  Ordering Results  HAVING – Filtering on Aggregate fields  Filtering on Aggregate and non-aggregate fields  DISTINCT
  • 3. COUNT(), SUM(), MIN(), MAX(), AVG()  function(expression) – Expressions generally column name  COUNT(x) – number of matching records, can be *, 1, column  SUM(x) – summation of expression or column per group  MIN(x) – minimum of expression value per group  MAX(x) – maximum of expression value per group  AVG(x) – average of expression value per group
  • 4. Aggregation Details  Accounting for NULLs  Grouping on Multiple Fields  ORDER BY on Aggregate Fields
  • 5. HAVING - Filtering on Aggregate Fields  The ‘HAVING’ clause  Including non-Aggregate field in filtering
  • 6. DISTINCT - Filtering on Aggregate Fields  The ‘DISTINCT’ clause  How to include with COUNT(), MIN(), MAX(), AVG()  Does it account for NULLS?
  • 8. SELECT DateRecorded, VoteID, COUNT(User) AS [Count] FROM VoterTable GROUP BY DateRecord, VoteID;
  • 9. Question 2  Total Cost of inventory on hand?
  • 11. Any Questions?  COUNT(), SUM(), MIN(), MAX(), AVG()  Accounting for NULLs  Grouping on multiple fields  Ordering Results  HAVING – Filtering on Aggregate fields  Filtering on Aggregate and non-aggregate fields  DISTINCT