So far, results returned by
SELECT queries have been a list of records, that is, specific data rather than summaries or overviews. This chapter examines two main things: sorting data into groups and returning the data for that group as a whole, and aggregation functions available in SQL. Aggregation is another way of saying a summary of data. For example, aggregating data might involve finding the average age of film club members or counting how many members live in a particular state. What you've learned so far allows you to answer questions pertaining to which film categories each member likes or what John Jones's favorite film category is. However, by the end of this chapter, using a combination of groups and aggregation will enable you to answer questions such as how many members like thrillers. The difference between grouping and aggregation is that grouping finds out information about a particular record, whereas aggregation summarizes more than one record.
Specifically, this chapter covers the
GROUP BY clause, which groups results according to the parameters set forth in the clause. Additionally, this chapter examines the
COUNT() function, which counts records; the
SUM() function, which adds the value of records together; the
AVG() function, which finds averages; and finally, the
MIN() functions, which find the lowest and highest values in a set of records, respectively. The chapter begins by looking at grouping results with ...