Skip to Main Content
SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL, Second Edition
book

SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL, Second Edition

by John L. Viescas, Michael J. Hernandez
September 2007
Intermediate to advanced content levelIntermediate to advanced
672 pages
13h 23m
English
Addison-Wesley Professional
Content preview from SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL, Second Edition

The GROUP BY Clause

As you discovered in Chapter 12, you can find out all sorts of interesting information by using aggregate functions. However, you might have noticed that all the examples we gave you applied the aggregate functions across all the rows returned by the FROM and WHERE clauses. You could filter the result set down to one group using the WHERE clause, but there was really no way to look at the results from multiple groups in one request. To accomplish this summarizing by group in a single request, we need to add one more major clause to your SQL vocabulary—GROUP BY.

Syntax

Let’s take a close look at the GROUP BY clause. Figure 13-1 shows the basic diagram for a SELECT statement with GROUP BY added.

Figure 13-1. The syntax diagram ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

SQL Queries for Mere Mortals®: A Hands-On Guide to Data Manipulation in SQL, Third Edition

SQL Queries for Mere Mortals®: A Hands-On Guide to Data Manipulation in SQL, Third Edition

John Viescas, Michael J. Hernandez
Effective SQL: 61 Specific Ways to Write Better SQL, First Edition

Effective SQL: 61 Specific Ways to Write Better SQL, First Edition

John L. Viescas, Douglas J. Steele, Ben G. Clothier
SQL for Data Analytics

SQL for Data Analytics

Upom Malik, Matt Goldwasser, Benjamin Johnston

Publisher Resources

ISBN: 9780321444431Purchase book