aggregating data

11
Aggregating Data Presented by Aaron Buma

Upload: aaron-buma

Post on 20-Jan-2017

604 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Aggregating data

Aggregating Data

Presented by Aaron Buma

Page 2: Aggregating data

AgendaCOUNT(), SUM(), MIN(), MAX(), AVG()

Accounting for NULLsGrouping on multiple fieldsOrdering Results

HAVING – Filtering on Aggregate fieldsFiltering on Aggregate and non-aggregate

fieldsDISTINCT

Page 3: Aggregating data

COUNT(), SUM(), MIN(), MAX(), AVG()function(expression) – Expressions generally column

nameCOUNT(x) – number of matching records, can be *, 1,

columnSUM(x) – summation of expression or column per groupMIN(x) – minimum of expression value per groupMAX(x) – maximum of expression value per groupAVG(x) – average of expression value per group

Page 4: Aggregating data

Aggregation DetailsAccounting for NULLsGrouping on Multiple FieldsORDER BY on Aggregate Fields

Page 5: Aggregating data

HAVING - Filtering on Aggregate FieldsThe ‘HAVING’ clauseIncluding non-Aggregate field in filtering

Page 6: Aggregating data

DISTINCT - Filtering on Aggregate FieldsThe ‘DISTINCT’ clause

How to include with COUNT(), MIN(), MAX(), AVG()Does it account for NULLS?

Page 7: Aggregating data

Question 1

Page 8: Aggregating data

SELECT DateRecorded,VoteID,COUNT(User) AS [Count]

FROM VoterTable GROUP BY DateRecord,

VoteID;

Page 9: Aggregating data

Question 2Total Cost of inventory on hand?

Page 10: Aggregating data

Question 2

Page 11: Aggregating data

Any Questions?COUNT(), SUM(), MIN(), MAX(), AVG()

Accounting for NULLsGrouping on multiple fieldsOrdering Results

HAVING – Filtering on Aggregate fieldsFiltering on Aggregate and non-aggregate

fieldsDISTINCT