Chapter 5 – Aggregation

“Hadoop climbed Aggregate Mountain and delivered a better way to Sum It.”

- Tera-Tom Coffing

Quiz – You calculate the Answer Set in your own Mind

image

SELECTAvg(Grade_Pt)AS "AVG"

,Count(Grade_Pt)  AS "Count"

,Count(*)                 AS "Count *"

FROM         Student_Table

WHERE      Class_Code IS NULL

AVG    Count     Count * 

What would the result set be from the above query? The next slide shows answers!

Answer – You calculate the Answer Set in your own Mind

image

SELECTAvg(Grade_Pt)AS "AVG"

,Count(Grade_Pt)  AS "Count"

,Count(*)                 AS "Count *"

FROM         Student_Table

WHERE      Class_Code IS NULL

image

Here are your answers!

There are Five Aggregates

image

The five aggregates are listed above.

Quiz – How many Columns and Rows come back?

image

How many columns and rows will the above query produce in the result set?

Answer – How Many Columns and Rows Come Back?

image

How many rows will the above query produce in the result set? The answer is one.

Quiz – What Happens with This Query?

image

If you have a normal column (non aggregate) in your query, you must have a corresponding GROUP BY statement.

Answer to Quiz – What Happens With This Query?

image

If you have a normal column (non aggregate) in your query, you must have a corresponding GROUP BY statement.

GROUP BY when Aggregates and Normal Columns Mix

image

If you have a normal column (non aggregate) in your query, you must have a corresponding GROUP BY statement.

GROUP BY Delivers one row per Group

image

Group By Dept_No command allow for the Aggregates to be calculated per Dept_No. The data has also been sorted with the ORDER BY statement.

Limiting Rows and Improving Performance with WHERE

image

Will Dept_No 300 be calculated? Of course you know it will . . . NOT!

Keyword HAVING tests Aggregates after they are Totaled

image

The HAVING Clause only works on Aggregate Totals. The WHERE filters rows to be excluded from calculation, but the HAVING filters the Aggregate totals after the calculations, thus eliminating certain Aggregate totals.

Getting the Average Values Per Column

image

The query retrieved the average rows per value for the column Product_ID.

Average Values Per Column for all Columns in a Table

image

The query above retrieved the average rows per value for both columns in the table.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset