SQL Puzzles and Answers (2nd Edition) cover

SQL Puzzles and Answers (2nd Edition)

No rating yet
Word count
490K words
Chapters
40
Series
Turing Programming Series · Database Series
ISBN
9787115174345

Tags

Summary

SQL Puzzles and Answers (2nd Edition) is a puzzle-collection style work by American database expert Joe Celko. The Chinese edition, translated by Mi Quanxi and published by Posts & Telecom Press in 2008, belongs to the Turing Programming Series · Database Series. The book is built around 75 SQL problems abstracted from real business scenarios, covering topics that range from fiscal-year reports, absence and attendance records, access-control card swipes, hotel room reservations, portfolio tracking, printer job scheduling, payroll and income tax calculations, inventory adjustments, moving averages and depreciation, merging contiguous ranges, string sorting and report formatting, to classic algorithmic puzzles such as Sudoku solving and the stable marriage problem. Each puzzle first presents the table structures and data along with a statement of requirements, then the author offers one or more solutions based on SQL-99 and later standards, comparing different approaches in terms of readability, portability, and execution efficiency; an index at the end of the book makes it easy to look things up by topic. Its focus is not on cataloguing syntax but on training readers to "translate" real-world requirements into set operations and relational operations, which is why readers often use it as a workout book for SQL fundamentals and why it also serves well as a supplementary case collection for university database courses.

Editor's review

市面上的SQL书大致分两类:一类讲语法和调优规则,一类讲“怎么想”。这本书属于后一类,而且做得相当彻底——它不给你成套的知识体系,只给你75个刁钻但真实的业务问题,然后让你自己写下答案,再去看Joe Celko 怎么解。 作者的资历决定了这本书的底气:他在ANSI SQL标准委员会任职十年,习惯从标准与集合论的角度看问题,所以同一个需求他往往能给出两三种写法,并说明哪种更符合关系模型、哪种只是依赖某个数据库的方言。这种“多解对照”对已经会写SQL、却总在复杂报表前卡壳的人特别有用。 中文版由米全喜翻译,沿用第2版的75个谜题结构,题面配表结构和数据,代码基本可在多种数据库上运行。书并不厚,但每一题都值得动手做一遍——把它当习题册做,比当读物翻,收获会大得多。

Who it's for

A good fit for

  • 已能写出单表查询、联接与简单聚合,想突破复杂报表的中级SQL使用者
  • 日常需要写财务、库存、排班、统计类报表的数据开发与后端工程师
  • 希望用真实案例讲解关系运算与集合思维的高校数据库课程师生
  • 喜欢通过做题和对照答案来学习,而不是读理论推导的读者

Not a good fit for

  • 从未写过SELECT语句的零基础读者,需要先补语法与建表基础
  • 只想查阅某个数据库(如MySQL或SQL Server)专属语法与调优参数的人
  • 期待系统讲解数据库设计范式、事务与索引原理的读者

Reading tips

  1. 先看题目和数据,自己动手写出解法,再看作者答案逐条对比思路差异,效果远胜直接读解法。
  2. 不必从头到尾逐题阅读,可按工作场景挑题(如财务、库存、排班),或按主题归类练习。
  3. 遇到依赖方言的写法时,回到自己常用的数据库实测一遍,留意标准SQL与方言的边界。
  4. 配合作者同系列的《SQL编程风格》一类的书一起读,把解题技巧沉淀为可复用的编码规范。

About the publisher

Posts & Telecom Press China · Founded in 1953

Posts & Telecom Press is known for its strengths in science and technology, computing, and information and communications titles, and has extended its publishing into photography, art, software learning, and inspirational growth, giving it a fairly diverse range. Its catalog includes computing and communications works such as Refactoring and Patterns (Revised Edition) and Huawei Switch Learning Guide (Second Edition), alongside bilingual collector's editions such as The Little Prince (Chinese-English-French illustrated collector's edition), The Great Gatsby, and Three Days to See. Beijing Ten Years: 1980-1990 and Ghost Blade: WLOP Personal Illustration Collection reflect its presence in photography and art. Its authors include Antoine de Saint-Exupéry, Helen Keller, Joshua Kerievsky, Wang Da, Zhang Zhaozeng, and WLOP.

Contents

  1. Puzzle 1 The Fiscal Year Table
  2. Puzzle 2 Absentees
  3. Puzzle 3 The Anesthesiologist Puzzle
  4. Puzzle 4 Access-Control Cards
  5. Puzzle 5 Alphabetic Data
  6. Puzzle 6 Hotel Room Reservations
  7. Puzzle 7 Tracking a Portfolio
  8. Puzzle 8 Scheduling Printers
  9. Puzzle 9 Empty Seats
  10. Puzzle 10 Wages by Social Security Number
  11. Puzzle 11 Job Order
  12. Puzzle 12 Claim Status
  13. Puzzle 13 Teachers
  14. Puzzle 14 Telephones
  15. Puzzle 15 Finding the Last Two Paychecks
  16. Puzzle 16 Mechanics
  17. Puzzle 17 Employment Agency
  18. Puzzle 18 Advertising Letters
  19. Puzzle 19 Sales Champion
  20. Puzzle 20 Quiz Results
  21. Puzzle 21 Airplanes and Pilots
  22. Puzzle 22 Landlords
  23. Puzzle 23 Magazines
  24. Puzzle 24 One in Ten
  25. Puzzle 25 Milestones
  26. Puzzle 26 Data Flow Diagrams
  27. Puzzle 27 Finding Equal Sets
  28. Puzzle 28 Calculating the Sine Function
  29. Puzzle 29 Calculating the Mode
  30. Puzzle 30 Average Sales Waiting Time
  31. Puzzle 31 Buying All Products
  32. Puzzle 32 Calculating Taxes
  33. Puzzle 33 Calculating Depreciation
  34. Puzzle 34 Consultant Income
  35. Puzzle 35 Inventory Adjustments
  36. Puzzle 36 Dual Roles
  37. Puzzle 37 Moving Averages
  38. Puzzle 38 Ledger Updates
  39. Puzzle 39 Insurance Losses
  40. Puzzle 40 Permutations

FAQ

这本书适合零基础学SQL的人吗?
不太适合。书中默认读者已掌握SELECT、JOIN、GROUP BY等基础,直接进入复杂问题的多种解法。零基础读者建议先学一本入门教材,再回来把它当作练习册。
书中的代码能在MySQL或SQL Server上直接运行吗?
书中解法以SQL-99及更新标准为基础,多数写法具有可移植性,但部分谜题会涉及特定数据库的方言或特性。建议在自己使用的数据库上实测,遇到差异时查对应产品文档。
75个谜题需要按顺序读吗?
不需要。各谜题相对独立,可按业务场景或兴趣挑选。书末附有索引,也可按涉及的技术点(如区间合并、移动平均、字符串处理)检索。
这本中文版对应英文原书的哪一本?
对应Joe Celko的《Joe Celko's SQL Puzzles and Answers》。中文版由米全喜翻译,人民邮电出版社2008年出版,ISBN为9787115174345,共321页。
这本书和《SQL编程风格》是同一本吗?
不是。两者是作者不同的著作,前者是解题谜题集,后者侧重编码风格与规范。中文版均由人民邮电出版社引进,选购时注意核对书名与ISBN。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

Top rated in the same category