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

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

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

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

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

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

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

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

View Full DocumentRight Arrow Icon
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 HERE beer = ‘Bud’; WHERE beer = Bud ; 6
Background image of page 6
NULL’s Ignored in Aggregation • NULL never contributes to a sum, average, or td b t hi i count, and can never be the minimum or maximum of a column. • But if there are no non-NULL values in a column, en the result of the aggregation is NULL 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.

This note was uploaded on 02/17/2012 for the course CS 411 taught by Professor Winslett during the Spring '07 term at University of Illinois at Urbana–Champaign.

Page1 / 23

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

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