With the explosion of data, computing power, and cloud data warehouses, SQL has become an even more indispensable tool for the savvy analyst or data scientist. This practical book reveals new and hidden ways to improve your SQL skills, solve problems, and make the most of SQL as part of your workflow.
You'll learn how to use both common and exotic SQL functions such as joins, window functions, subqueries, and regular expressions in new, innovative ways--as well as how to combine SQL techniques to accomplish your goals faster, with understandable code. If you work with SQL databases, this is a must-have reference.
• Learn the key steps for preparing your data for analysis
• Perform time series analysis using SQL's date and time manipulations
• Use cohort analysis to investigate how groups change over time
• Use SQL's powerful functions and operators for text analysis
• Detect outliers in your data and replace them with alternate values
• Establish causality using experiment analysis, also known as A/B testing
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
【One-Line Pitch】
A practical, advanced SQL reference for analysts and data scientists who want to move beyond basic queries and use SQL as a complete toolkit for data preparation, time series analysis, cohort studies, text mining, and A/B testing—turning raw data into actionable insights.
【Book Arc】
- **Opening (~0%–10%)**: Introduces SQL's role in modern data analysis, framing it as a core skill within a broader data-informed workflow. Covers ethical considerations (GDPR, CCPA) and sets expectations for the book's practical, code-first approach.
- **Early (~10%–30%)**: Builds foundational knowledge: database types (row-store vs. column-store like Redshift, Snowflake), data types (BOOLEAN, DATE, TIMESTAMP), and query structure. Emphasizes data profiling—checking distributions, sampling, and understanding schemas before analysis.
- **Early–Middle (~30%–50%)**: Focuses on data preparation and shaping. Covers CASE statements for cleaning and categorizing (e.g., standardizing gender values, NPS scoring), handling nulls and empty strings, and techniques like pivoting/unpivoting. Introduces window functions (e.g., ntile) for ranking and binning.
- **Middle (~50%–70%)**: Delves into advanced analysis techniques: time series analysis with date/time manipulations, cohort analysis (retention curves, survivorship, repeat purchase behavior), and text analysis using SQL string functions and regular expressions. Emphasizes combining techniques for efficient, readable code.
- **Late (~70%–90%)**: Covers outlier detection and replacement, and experiment analysis (A/B testing) to establish causality. Discusses how to structure complex SQL for maintainability and how to output data for BI tools, statistics (R), or machine learning (Python).
- **Ending (~90%–100%)**: Wraps up with best practices for integrating SQL into a repeatable analysis workflow, emphasizing that data analysis is a continuous process, not a one-off project. (Excerpts do not cover the final chapters in detail.)
【Key Takeaways】
- **SQL is a complete analysis tool, not just a query language** (Early): Beyond fetching data, SQL can profile, clean, shape, and model data—reducing reliance on external tools. This saves time and leverages database computing power.
- **Data profiling is the first step in any analysis** (Early): Before querying, inspect schemas, column names, and distributions to build a mental model of relationships (e.g., order_detail → order → customer). This prevents errors and guides query design.
- **Column-store databases change how you write SQL** (Early): Databases like Redshift and Snowflake compress data efficiently and lack primary keys, so duplicates can sneak in. Understanding their write-only policies and lack of indexes is crucial for quality checking and query optimization.
- **CASE statements are the Swiss Army knife for data cleaning** (Middle): Use them to standardize messy values (e.g., 'F', 'female', 'femme' → 'Female') or create new categories (e.g., NPS detractors/passives/promoters). They handle multiple columns and AND/OR logic, making them versatile for enrichment.
- **Window functions like ntile are essential for ranking and binning** (Middle): ntile splits data into ordered bins (e.g., deciles of order amounts), enabling percentile analysis and cohort segmentation. Combined with PARTITION BY and ORDER BY, they unlock powerful aggregations without collapsing rows.
- **Handling nulls and empty strings is a deliberate choice** (Middle): Nulls mean "unknown," while empty strings mean "known blank." Business users often misinterpret nulls, so decide whether to replace them with defaults or meaningful values to avoid confusing output.
- **Shaping data depends on the downstream tool** (Middle): Output as few rows as possible while meeting granularity needs—whether for BI dashboards, spreadsheets, R, or Python ML models. This reduces data transfer time and processing overhead.
- **Time series and cohort analysis are core analytical patterns** (Late): SQL's date/time functions enable trend analysis, while cohort analysis (e.g., retention curves, survivorship) reveals how groups change over time. These techniques turn raw event logs into strategic insights.
【Reading Tips】
- **Skim the early chapters (0–30%)** if you're already comfortable with SQL basics; focus on the sections about column-store databases and data profiling, as they're unique and often overlooked.
- **Deep-read the middle chapters (30–70%)** on data shaping, window functions, and cohort analysis—these are the book's core value. Practice the code examples with your own data to internalize the patterns.
- **Pay special attention to the "why" behind each technique** (e.g., why use ntile vs. CASE for binning). The book explains trade-offs, which helps you choose the right tool for future problems.
- **Use the GitHub repository** (linked in the preface) to download code examples and exercises. Run them in your own database environment to see how syntax varies across SQL dialects (e.g., LIMIT vs. TOP).
- **Skip the preface and early ethics discussion** if you're time-pressed; they're context-setting but not actionable. Jump straight to Chapter 2 for data preparation techniques.
【Coverage Limits】
This guide synthesizes the book's core themes—data prep, time series, cohorts, text analysis, and A/B testing—but does not cover every code example or the final chapters' detailed case studies. For exhaustive syntax and edge cases, refer to the book directly.
Page 7
146 Defining Cohorts from Dates Other Than the First Date 151 Related Cohort Analyses 153 Survivorship 154 Returnship, or Repeat Purchase Behavior 158 Cumula...
llenges. Communicating results is a skill. Learning to make good recommendations and becoming a trusted partner to an organization take time. In my experienc...
eturns the remainder when one integer is divided by another. If the ID field is an integer, mod can be used to find the last one, two, or more digits and fil...
propriate. Empty string can also be used as a default value instead of null, or as a way to overcome a NOT NULL constraint by inserting a value, even if empt...
l databases 70 | Chapter 3: Time Series Analysis Figure 3-2. Trend of monthly retail and food services sales This data clearly has some patterns, but it also...
JOIN. In this example, the two table aliases are JOINed on the year of the sales_month to ensure that the aggregated values are for the same year, resetting...
e end date relative to the next start date—can be used when no end date is present and we have a reasonable expectation that most customers or users will sta...
aa JOIN ( SELECT generate_series as period FROM generate_series(0,20,1) ) cc on 1 = 1 ) aaa LEFT JOIN ( SELECT d.first_state, g.gender ,coalesce(date_part('y...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Add Tag
Enter tag name (max 50 characters)
Share E-Book
SQL for Data Analysis Advanced Techniques for Transforming Data into Insights (Cathy Tanimura) (Z-Library)
Scan QR code with your phone to access
Copy the link or scan the QR code to access this e-book on your phone
Share E-Book via Email
Please enter email address
Donation Statistics
¥.00
Total Donations
0
Donation Count
SQL for Data Analysis Advanced Techniques for Transforming Data into Insights (Cathy Tanimura) (Z-Library)
Find Your Favorite Books
Only registered users can comment after logging in. Comments need to be reviewed by administrators before being displayed
Loading comments...
Reply to Comment
Edit Comment