Non-Fiction, Informative, Educational

SQL for Data Analysts: Foundations eBook

A Coursebook on SQL for Data Analysts: Foundations

by Brooks Marco

  • English
  • 152 pages
  • 2026
  • SamEnrico

A Coursebook on SQL for Data Analysts: Foundations

Formats

Free sample

Chapter 1: The Analyst's Map...-- The first time you saw a spreadsheet with ten thousand rows, your eyes probably glazed over. The second time, you might have felt a flicker of curiosity. By the hundredth time, you realized something important: the answers you need are buried somewhere in those rows, but you lack a shovel. That shovel is SQL. Not just any SQL, though.

This book is not about becoming a database administrator or a backend engineer. You are here because you want to extract meaning, not just data. You want to tell stories with numbers, identify trends before they become obvious, and answer questions that stakeholders haven't even thought to ask yet. This chapter is not a dry list of syntax rules. It is a fundamental reorientation of how you think about data, queries, and your role as an analyst.

By the time you finish these pages, you will see spreadsheets, databases, and even CSV files differently. You will understand that SQL is not a programming language you tolerate; it is the primary tool for turning raw, messy reality into actionable insight. And you will have a working database environment ready to prove it.The Lingua Franca of Data Analysis Walk into any modern company that relies on data, and you will hear the same sounds. Not the hum of servers, but the rhythm of people asking questions. “How many users signed up yesterday?” “What is our month-over-month retention?” “Which marketing channel drove the highest lifetime value?” Behind each of those questions is a conversation happening in SQL.

Not because executives write SQL themselves, but because the analysts who serve them do. SQL has become the universal language of data work, transcending industries, tooling choices, and even programming language preferences. A Python developer and an R enthusiast might argue about many things, but they will both reach for SQL when they need to pull data from a production database. This is not an accident. SQL is declarative, meaning you describe what you want, not how to get it.

The database engine figures out the mechanics. This abstraction is precisely why analysts love SQL: you focus on the business question, not on loop optimization or memory management. For example, consider the question “Show me total sales by region for the last quarter.” In a procedural language, you might write twenty lines of code to iterate over rows, check dates, sum values, and handle edge cases. In SQL, you write three or four lines that read like almost like English. This declarative nature makes SQL the closest thing to a direct interface between human curiosity and machine-stored facts.Yet many newcomers misunderstand what makes SQL powerful for analysts specifically.

A software engineer uses SQL to support an application, often retrieving a single record or a small batch of rows. An analyst uses SQL to discover patterns across thousands, millions, or billions of rows. The difference is not just scale; it is mindset. The engineer asks, “Did user 12345 complete their purchase?” The analyst asks, “What percentage of users who viewed a product completed a purchase within seven days?” The first question seeks a fact. The second seeks an insight.

Throughout this book, every concept will be filtered through this analytical lens. When you learn WHERE filters, you will not just learn how to exclude rows; you will learn how to isolate meaningful segments. When you learn JOINs, you will not just learn how to combine tables; you will learn how to build a complete picture of customer behavior across disparate systems. When you learn window functions, you will not just learn syntax; you will learn how to answer “What changed compared to last week?” This mindset shift, more than any specific command, separates competent SQL users from exceptional data analysts.Two Kinds of Databases, Two Kinds of Thinking Before you write a single line of SQL, you need to understand the battlefield. Not all databases are created equal, and using the wrong type for the wrong job is like driving a Formula One car on a rocky trail.

The two primary categories you will encounter are OLTP and OLAP, and confusing them leads to frustration, slow queries, and incorrect assumptions.OLTP stands for Online Transaction Processing. These databases are built for speed on a massive number of small, simultaneous operations. Think of an e-commerce website during a flash sale. Every time someone adds an item to their cart, updates their quantity, applies a coupon, or completes a checkout, the OLTP database handles a tiny, fast transaction. The key characteristics are high concurrency, low latency, and strong data consistency.

You never want two customers to buy the last item in inventory simultaneously, so OLTP databases use locking mechanisms and transactions (often with ACID compliance) to prevent chaos. Typical OLTP databases include Postgre SQL, My SQL, and Microsoft SQL Server. Their schemas are often normalized, meaning data is spread across many small tables to avoid duplication. For example, a customer’s address might appear in one place, and every order references it by ID. This design saves storage and ensures updates happen in one location, but it requires multiple joins to answer analytical questions.OLAP stands for Online Analytical Processing.

These databases are built for complex, read-heavy queries that scan millions or billions of rows. Think of a business intelligence dashboard showing sales trends over five years. The query might sum revenue across thousands of products and hundreds of dates. OLAP databases use columnar storage, meaning each column’s data is stored together on disk, allowing the database to read only the columns you request. They also use sophisticated compression and parallel processing.

Examples include Amazon Redshift, Google Big Query, Snowflake, and Duck DB for local analysis. OLAP schemas are often denormalized, meaning data is stored in wider tables with repeated values to reduce the need for joins. This trade-off sacrifices storage efficiency for query speed on large aggregations.Why does this distinction matter to you as an analyst? Because the same SQL query written against an OLTP database might run instantly, but against a poorly designed OLAP schema might crawl. Or vice versa.

More importantly, you need to know which environment you are querying so you can set appropriate expectations. If you run a heavy aggregation on an OLTP database during business hours, you might slow down the live application and anger the engineering team. If you run a poorly optimized query on an OLAP database, you might incur unexpected costs on a cloud platform that charges by the amount of data scanned. Throughout this book, we will focus primarily on Postgre SQL as our teaching database. It is a robust, open-source OLTP database that also handles analytical workloads reasonably well for learning purposes.

However, we will consistently point out when a particular technique is more suitable for OLAP systems and when you might need to adapt your approach.The Analyst’s Workflow: From Question to Decision Every analysis follows the same invisible arc, whether you are calculating monthly sales or predicting customer churn. Recognizing this arc helps you structure your SQL queries before you write them and prevents the common mistake of writing first and thinking later. The arc consists of four stages: Question…

This is the end of the free sample. Get the eBook to keep going. Buy now

About this book

A Coursebook on SQL for Data Analysts: Foundations

Details

Author
Brooks Marco
Publisher
SamEnrico
Language
English
Genre
Non-Fiction, Informative, Educational
Released
2026-06-02
Pages (approx.)
152
Available as
eBook, Audiobook

Read better in the ZLOADR app

Your eBooks on your phone or tablet. Sign in with your SamEnrico account and start reading.

More by Brooks Marco

See all