SQL for Business Analysis商業分析 SQL

Preface前言

SQL is how analysts get answers out of a company’s databases, and job advertisements for analyst roles usually list it first. AI can now write much of the code. What still takes judgement is knowing whether a query answers the question that was asked, and this tutorial is built around that.

SQL 是分析師從公司數據庫取得答案的工具,分析職位的招聘廣告通常把它列在第一位。現在 AI 已經可以寫出大部分程式碼,但判斷一條查詢是否真正回答了被問的問題,仍然需要人的判斷。本教程正是圍繞這一點而設計。

All chapters use the data of one fictional wholesale company: eight tables of customers, suppliers, parts and orders, based on the TPC-H benchmark. Each chapter starts with a question someone in the business would ask. The queries run in your browser, so you can change any of them and run it again. In places the data is messy on purpose, as real data is, and the chapters show where a plausible query goes wrong.

所有章節都使用同一家虛構批發公司的數據:八張關於客戶、供應商、零件和訂單的表,以 TPC-H 基準測試為基礎。每一章都從公司裏某個人會問的問題開始。查詢在你的瀏覽器中執行,你可以修改任何一條查詢再重新執行。部分數據刻意保留了真實數據常見的混亂,各章會指出看似合理的查詢在哪裏出錯。

No programming experience is needed. If you have used a spreadsheet, the early chapters compare each idea with Excel and point out where the comparison stops working. The tutorial is published one part at a time.

閱讀本教程不需要任何編程經驗。如果你用過電子試算表,前幾章會把每個概念與 Excel 比較,並指出這種比較在甚麼地方不再適用。本教程會逐個部分發佈。

Contents目錄

Part 1Tables and single-table queries表與單表查詢

  1. Chapter 1What a table really is一張表到底是甚麼
  2. Chapter 2Filtering and sorting篩選與排序
  3. Chapter 3Calculated columns計算欄
  4. Chapter 4Summarising with GROUP BY用 GROUP BY 匯總Coming
  5. Chapter 5NULL: the value that isn’t thereNULL:不存在的值Coming

Later parts

  1. Part 2Joining tables連接多張表
  2. Part 3Multi-step logic and window functions多步驟邏輯與窗口函數
  3. Part 4Cleaning and deduplication數據清洗與去重
  4. Part 5Analysis patterns and metrics分析模式與指標
  5. Part 6Working with AI and other tools與 AI 及其他工具協作
  6. Part 7Data modelling and dbt數據建模與 dbt