liveBook · Manning

SQL

As explained in Effective Data Analysis

A SQL query is a statement written in SQL that retrieves, filters, combines, or modifies data in a database.

SQL (structured query language) is a practical way to access and manipulate data in a data warehouse. Analysts use it to draw from tables and views: tables hold records in rows and fields in columns, while views present curated query results that may combine underlying tables. Schemas organize tables. section 1.2.2

SELECT     #1
    state,
    SUM(population) AS total_population
FROM city_populations
GROUP BY state

city_populations %>%    #2
    group_by(state) %>%
    summarise(total_population = sum(population))

city_populations.groupby('state')['population'].sum()     #3

Compare three ways to calculate total population by state. The SQL query selects a state, sums its population, and groups the result by state; the adjacent R and Python expressions perform the same aggregation. The listing is illustrative rather than runnable without the table. section 1.2.2

Familiarity with SQL can help an analyst explore an unfamiliar warehouse, although functions—particularly date functions—may differ between SQL dialects. SQL is also used to define schemas and tables, including their columns, data types, and constraints. In dbt, a model can combine a SQL query with table metadata and Jinja references to other models or warehouse sources. section 1.2.2 section 11.3.1

Keep the queries behind an analysis understandable and reusable. Recording how data was retrieved helps colleagues reproduce the work, supports stakeholder follow-ups, and avoids rewriting queries later. For a promotion analysis, documentation could identify the warehouse datasets used, explain exclusions, and describe the queries that retrieved the data. section 2.3.2 section 2.3.3

How Effective Data Analysis covers it

How deep it goes
Explains warehouse objects and a grouped aggregation, then describes SQL-defined tables and dbt models without providing a full syntax guide.
Examples
Compares population-by-state aggregation in SQL, R, and Python and asks how to document queries for a promotion analysis.
What it assumes
Introduces tables, views, and schemas while treating prior SQL familiarity as useful, not essential, for entering an unfamiliar warehouse.
What you can do after
Apply it via SQL queries to access and aggregate warehouse data, and document those queries for reproducible analysis.
How it connects
Links SQL to data warehouses, tables, views, schemas, R and Python data manipulation, and dbt models.

Also explained in

Compare how 25 books explain SQL →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Data Analysis. The section links point to the parts of the book it draws on.