Skip to Content
《Head First SQL》 (Chinese Edition), 2nd Edition
book

《Head First SQL》 (Chinese Edition), 2nd Edition

by Kimberly Fessel
June 2026
740 pages
13h 7m
Chinese
O'Reilly Media, Inc.
Content preview from 《Head First SQL》 (Chinese Edition), 2nd Edition

第 7 章 数据 分组:汇总类别

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

Image

准备好创建自己的分组了吗?到目前为止,你应该已经对处理 SQL 数据的能力充满信心了。我们认为你已经准备好大显身手,并在你的查询中迎来一位新“嘉宾”:GROUP BY 子句。本章将介绍 构建和分析表数据分组。如果这些分组必须满足特定条件才能进入你的“出席名单”,那么总有 HAVING 子句可以 过滤分组结果。我们甚至会教你一个经典的记忆法,确保聚会中的各子句都能按 预定的 SQL 顺序。数据表已准备就绪,数据也已就位,我们还已发出群组邀请——快来加入吧。

尽快进行分组聚合

当你帮助乔什的母亲斯泰西收集就业信息时,你和乔什在达塔维尔镇议会中建立了相当不错的数据处理声誉。事实上,乔什刚刚收到了一封来自他母亲的议会同事奥尔蒂斯先生发来的紧急邮件:

Image
Image

SUM 配合 WHERE

Image

如果乔什只需要找出在汽车维修店就业的人数总和,他可以在WHERE查询中添加一个SUM子句。你的关系型数据库管理系统(RDBMS)会先筛选出汽车维修店的相关行,然后对SUM”列中剩余的值应用employees函数。

Image
Image

现在,乔什只需针对表中的每类店铺编写一个类似的查询……真的需要这样吗?

确实需要。

如果你想获取每个组的汇总数据,其实不必为每个类别单独编写 SQL 查询。相反,你可以使用 ...

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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
How to Overcome a Power Deficit

How to Overcome a Power Deficit

Cyril Bouquet, Jean-Louis Barsoux
Relational Power Is the New Currency of Hybrid Work

Relational Power Is the New Currency of Hybrid Work

Lebene Soga, Yemisi Bolade-Ogunfodun, Nazrul Islam, Joseph Amankwah-Amoah

Publisher Resources

ISBN: 0642572408114