Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: MICK

Rating No ratings yet

本书是《SQL基础教程》作者MICK为志在向中级进阶的数据库工程师编写的一本SQL技能提升指南。全书可分为两部分,第一部分介绍了SQL语言不同寻常的使用技巧,带领读者从SQL常见技术,比如CASE表达式、自连接、HAVING子句、外连接、关联子查询、EXISTS……去探索新发现。这部分不仅穿插讲解了这些技巧背后的逻辑和相关知识,而且辅以丰富的示例程序,旨在帮助读者提升编程水平;第二部分着重介绍关系数据库的发展史,把实践与理论结合起来,旨在帮助读者加深对关系数据库和SQL语言的理解。此外,每节末尾均设置有练习题,并在书末提供了解答,方便读者检验自己对书中知识点的掌握程度。

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A practical bridge from everyday SQL to genuinely set-based thinking: it turns familiar clauses like CASE, HAVING, and EXISTS into sharper tools, then explains why the relational model works the way it does. Best for developers and DBAs who already write SQL but want to reason about it rather than memorize it. 【Book Arc】 - **Opening (~0%–15%)**: Starts with "unusual" uses of ordinary SQL—CASE expressions for flexible grouping and constraints, self-joins for ranking and deduplication, and the shift from row-by-row thinking to set thinking. Solves the problem of writing correct SQL for awkward reporting and ranking tasks. - **Early (~15%–35%)**: Moves into three-valued logic and NULL, HAVING as a tool for inspecting whole sets, and outer joins for building cross-tab and horizontal layouts. Solves the "why is my result empty / wrong?" class of bugs. - **Middle (~35%–55%)**: Covers set operations (UNION/INTERSECT/EXCEPT, set equality, relational division), EXISTS and quantified predicates, and handling ordered data such as sequences and dates. Solves problems that resist simple joins or aggregates. - **Late (~55%–75%)**: Applies the same techniques to cumulative sums, moving averages, overlapping intervals, and other window-like calculations done without window functions. Solves time-series and interval questions in portable SQL. - **Ending (~75%–100%)**: Shifts from technique to theory—the history of relational databases, Codd and Date's ideas, logic and set theory behind SQL, the "abolish NULL" debate, and recursion/hierarchies. Solves the "why does SQL look like this?" question and prepares readers for deeper study. 【Key Takeaways】 - **CASE is a general-purpose expression, not just a display formatter** (Opening): it can drive GROUP BY, embed logical implications in CHECK constraints, and replace rigid view-based mappings. - **Self-joins and correlated subqueries are how SQL ranks and compares rows** (Opening): treating one table as two named sets is the mental move that unlocks ranking, deduplication, and row-to-row comparison. - **NULL follows three-valued logic, and that changes query results** (Early): NOT IN with a NULL, ALL versus MIN/MAX, and empty-set inputs all behave counterintuitively; the book explains the truth tables behind them. - **HAVING inspects the set, WHERE inspects the elements** (Early): this distinction is the key to questions like "which groups are entirely complete?" and to finding gaps in sequences. - **Outer joins and scalar subqueries build cross-tabs and horizontal reports** (Early): the book shows both approaches and their trade-offs in readability and performance. - **Set operations have algebraic properties worth knowing** (Middle): UNION and INTERSECT are idempotent, EXCEPT is not, and set equality can be tested via idempotence or one-to-one mapping. - **EXISTS expresses quantification, including universal claims via double negation** (Middle): "all rows satisfy X" becomes "no row fails X," a pattern that generalizes to many puzzles. - **Ordered data can be handled with sets and predicates** (Middle/Late): generating sequences, finding gaps, cumulative sums, and overlapping intervals are all done without procedural loops. 【Reading Tips】 - Read Part 1 sequentially; each section builds on the previous technique, and the exercises at section ends are worth doing rather than skimming. - Deep-read the NULL and three-valued logic sections—they explain many real-world bugs and are referenced repeatedly later. - Skim the historical and philosophical chapters on a first pass, then return after finishing Part 1; they make more sense once the techniques are familiar. - Keep a scratch database handy; most examples are short enough to run and modify, which is where the learning happens. - Treat the exercises and answers as a self-check, not optional extras—they reveal whether you actually absorbed the set-based reasoning. 【Coverage Limits】 This guide is based on stratified excerpts covering roughly the first half of the book in detail, with later chapters represented mainly by table-of-contents entries and brief mentions. Specific examples, chapter numbering, and the full depth of the relational-history chapters are not fully covered here.
Excerpt 1
单位有都、道、 府、县,包含一都(东京都)、 等地区为单位来分组,并统计人口数量。具体来说,就是统计下表 PopTbl 二府(京都府和大阪府)、一道 中的内容,得出如右表“统计结果”所示的结果。 (北海道)和诸多的县,统称都 道府县。多个较近的县被划归到 ■ 统计结果 B 一个地区,如关东地区、九州地 ■ 统计数...
View in text
Excerpt 2
4 关东 柠檬 100 1 关东 菠萝 100 1 关东 苹果 100 1 关东 葡萄 70 4 关西 柠檬 70 1 关西 西瓜 30 2 关西 苹果 20 3 解法还是有使用窗口函数和自连接这两种(如果把标量子查询与连接 结合起来的解法当成另一种,那就有 3 种解法)。请分别思考一下。 ●练习题 1-2-3...
View in text
Excerpt 3
1 1992 52 1993 52 1994 50 1995 50 1996 49 1997 55 ■ 年营业额的趋势 请根据这张表里的数据,使用 SQL 输出与上一年相比营业额是增加 了还是减少了,抑或是没有变化。可以先试试求出“不变”这种情况。从 表里可以看到,我们需要求出的是 1993 年和 1995 年。...
View in text
Excerpt 4
分以上,但是数学考了 40 分,所以不符合 条件。 解法是,将查询条件“所有科目分数都在 50 分以上”转换成它的双 重否定“没有一个科目分数不满 50 分”,然后用 NOT EXISTS来表示转换 后的命题。 SELECT DISTINCT student_id FROM TestScores TS1 WHER...
View in text
Excerpt 5
m_no) FROM Items; 因为 item_no是表 Items 的唯一索引,所以效果更好。对于联合索引, 只要查询条件是联合索引的第一个字段,索引就是有效的,所以也可以对 表 SalesHistory 的 sale_date 字段使用极值函数。 这种方法并不是去掉了排序这一过程,而是优化了排序前的查找速...
View in text
Excerpt 6
CT子句查询 不到一条数据,然而这时会返回“空集”,而不是不返回任何内容。只不过, 因为我们没法实际看到,所以不好确认。仿照 UNIX 起名字的话,关系数 据库的这个特性可以叫作“泛关系主义”。 上面两个例子中的封闭性原本是来自数学的概念。数学中会根据“对 于什么运算是封闭的”这样的标准,将集合分为各种类型。这些...
View in text
Excerpt 7
他列的统计。从这一点上来说,各个列之间是相 互独立的。因此,我们分别按照“全国”“四国”这样的条件进行汇总就 可以了。 SELECT sex, SUM(population) AS total, SUM(CASE WHEN pref_name = '德岛' THEN population ELSE 0 END)...
View in text
Excerpt 8
不是字符串类型,可以先转换成字符串类型再拼 凑。这种解法怎么说呢,多少有点欺骗数据库的感觉……所以说,还是不 要多想了。需要扩展成三个字段以上时,同样地拼凑起来就可以了。 顺便说一下,也许有人会考虑下面这种解法。但是很遗憾,这么做是 错的。 -- 选择(材料,原产国)组合有重复的生产地:错误的查询语句 SELEC...
View in text
Tags
AI categories
DatabaseSQLProgramming Language
ISBN: 7115470529
Publish Year: 2017
Language: Chinese
File Format: PDF
File Size: 5.8 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…