cs411-06b-sql2-new

cs411-06b-sql2-new - CS411 Database Systems 06b: SQL-2...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS411 Database Systems 06b: SQL-2 Grouping and Aggregation
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Why Do We Learn This?
Background image of page 2
3 Q: What is “aggregate”?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Aggregations • SUM, AVG, COUNT, MIN, and MAX can be applied to a column in a SELECT clause to produce that aggregation on the column. • Also, COUNT(*) counts the number of tuples.
Background image of page 4
5 Example: Aggregation • From Sells(bar, beer, price), find the average price of Bud: SELECT AVG(price) FROM Sells WHERE beer = ‘Bud’;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Eliminating Duplicates in an Aggregation • DISTINCT inside an aggregation causes duplicates to be eliminated before the aggregation. • Example: find the number of different prices charged for Bud: SELECT COUNT(DISTINCT price) FROM Sells WHERE beer = ‘Bud’;
Background image of page 6
7 NULL’s Ignored in Aggregation • NULL never contributes to a sum, average, or count, and can never be the minimum or maximum of a column. • But if there are no non-NULL values in a column, then the result of the aggregation is NULL.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 22

cs411-06b-sql2-new - CS411 Database Systems 06b: SQL-2...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online