Need to produce a result with one tuple per director

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: produce a result with one tuple per director 1. Partition relation into subsets of tuples based on grouping column(s) 2. Apply function to each such group independently 3. Produce one tuple per group GROUP BY clause to specify grouping attributes SELECT director, COUNT(*) FROM Film WHERE year > 2001 GROUP BY director; • Every selector in SELECT clause must be a grouping column or an aggregation function 7 • e.g., SELECT director, year, COUNT(*) would not be allowed unless also grouping by year i.e., GROUP BY director, year HAVING CLAUSE After partitioning into groups, whole partitions can be discarded. • Provides a condition on the grouped tuples Having clause cannot reference individual tuples within group • Can reference grouping column(s) and aggregates only Contrast WHERE clause to HAVING clause 9 Note: As for aggregation, no GROUP BY clause means relation treated as one group ORDERING OF QUERY RESULTS Final output of a query can be sorted by one or more column values Use ORDER BY clause • Keyword DESC for descending order of values • Optionally use keyword ASC for ascending order (default) • Note that this is sorted ascending by department. ...
View Full Document

This document was uploaded on 02/07/2014.

Ask a homework question - tutors are online