SQL Data Analyst eBook
A Coursebook on SQL Data Analyst
by Royal Kathey
A Coursebook on SQL Data Analyst
Formats
Free sample
Chapter 1: The Set-Based Secret--–- Most people learn data analysis backward. They open Excel, stare at a grid of cells, and start clicking. They filter here, sort there, write a formula that references cell B2, then drag it down to B1000. It feels natural because that's how our brains work—one step at a time, one row after another, one cell after its neighbor.That procedural instinct is precisely what will fail you as a SQL analyst.Welcome to the single most important mental shift you will make in your entire data career. Before you write your first SELECT statement, before you install a single piece of software, you must abandon the思维方式 of the spreadsheet and adopt the mindset of the database.
This chapter is not about syntax. It is about rewiring how you think about data itself.The difference between someone who struggles with SQL for years and someone who becomes a confident, job-ready analyst in weeks is not intelligence or memory. It is the ability to think in sets. Every successful query you will ever write flows from this single insight: SQL does not operate on rows one at a time. It operates on entire sets of rows simultaneously.Imagine being asked, "Show me our top 10 customers by total spending." The spreadsheet user thinks: "Let me sort the customer column, then find the spending column, then look for the biggest numbers, then copy them somewhere." That is a sequence of instructions.
The SQL analyst thinks: "Take the entire set of customers. Calculate total spending for each one as a set. Sort that entire set by spending descending. Then return the first 10 rows of that sorted set."The difference is subtle but profound. One thinks in steps.
The other thinks in sets. This chapter will teach you to become a set-based thinker.Why Your Excel Intuition Is Lying to You You have been trained by spreadsheets to believe that data lives in a two-dimensional grid where every cell has an address like A1 or F42. You believe that calculations flow downward and rightward. You believe that if you want to know something about customer 537, you find row 537 and look across.SQL databases do not work that way. At all.A relational database is a collection of tables, and each table is an unordered set of rows.
There is no row 1, row 2, or row 537 in any meaningful sense. There is no "next cell over." There is no drag-down formula. The database does not remember the order in which you inserted rows, and it does not care.When you write a query, you are describing the shape of the result set you want. You are not telling the database how to compute it. You are telling the database what you want, and the database figures out the most efficient way to get it.This distinction—between declaring what you want versus instructing how to get it—is the fundamental divide between procedural programming (Excel macros, Python scripts, Java) and declarative programming (SQL).
As a data analyst, you are not a programmer telling the computer what to do step by step. You are a strategist describing the desired outcome.Consider this question: "Which customers have placed more than five orders in the last 90 days?"The procedural thinker writes a mental loop: "Start with an empty list. For each customer, count their orders in the last 90 days. If the count is greater than five, add the customer to the list. Then return the list."The set-based thinker writes: "From the set of customers, keep only those where the count of orders from the last 90 days is greater than five."The SQL query for that set-based thought is remarkably close to the English description.
You will learn the exact syntax in Chapter 3, but the shape of the query already makes sense:sql Copy Download SELECT customer_name FROM customers WHERE ( SELECT COUNT(*) FROM orders WHERE orders.customer_id = customers.customer_id AND order_date > CURRENT_DATE - INTERVAL '90 days' ) > 5;Notice what is missing: loops, conditionals, temporary variables, or instructions about how to traverse tables. You simply declare the relationship between customers and orders and let the database engine do the heavy lifting.This is the power of set-based thinking. And it is the secret that separates competent analysts from great ones.Databases Are Not Spreadsheets: OLTP vs. OLAPBefore you query any database, you need to understand what kind of database you are dealing with. There are two primary categories, and confusing them will lead to disastrous results.OLTP (Online Transaction Processing) databases are designed for speed, accuracy, and high volumes of small operations.
Every time you buy something online, update your shipping address, or like a social media post, you are hitting an OLTP database. These databases are optimized for INSERT, UPDATE, and DELETE operations—changing data quickly and reliably.The characteristics of an OLTP database include:Thousands of small, fast transactions per second Highly normalized tables (many tables, few columns each)Row-level locking to prevent conflicts Excellent for recording what is happening right now Terrible for complex analytical queries If you run a 30-minute analytical query on a live OLTP database during business hours, you will slow down or crash the company's core operations. The database will lock tables that the website needs to access. Customers will see timeouts. Your manager will receive angry emails.
You will learn a very painful lesson.OLAP (Online Analytical Processing) databases—often called data warehouses—are designed for the exact opposite workload. They are optimized for reading large volumes of data, aggregating millions of rows, and performing complex calculations. OLAP databases are refreshed periodically (nightly, hourly, or in real-time via streams) from OLTP source systems.The characteristics of an OLAP database include:Fewer, wider tables (denormalized for faster reads)Columnar storage (compression and faster aggregation)Designed for queries that scan millions of rows No live transactions happening while you query Perfect for answering business questions about what happened As a data analyst, you will spend 95% of your time querying OLAP databases. Your job is to extract insights from historical data, not to mess with live transactions. If someone gives you credentials to a database named production, transactional, or oltp_app, ask clarifying questions before running any query.
If the database ends in _warehouse, _analytics, or _dwh (data warehouse), you are in the right place.The Three Shapes of Data: Structured, Semi-Structured, and Unstructured SQL excels at structured data—information that fits neatly into rows and columns. Every row in a table has the same columns, and every column has a defined data type (integer, text, date, etc.). This is the world of customers, orders, products, and inventory.But the real world is messier. Understanding the three shapes of data will help you recognize when SQL is the right tool and when you need something else.Structured data (95% of what you will analyze as a SQL analyst) looks like a spreadsheet that went to graduate school. Every column has a name, a type, and constraints.
Every row conforms to the same schema. Examples include:A table of customer addresses with columns for street, city, state, and postal code A table of product sales with columns for date, product…
This is the end of the free sample. Get the eBook to keep going. Buy now
About this book
Details
- Author
- Royal Kathey
- Publisher
- SamEnrico
- Language
- English
- Genre
- Non-Fiction, Informative, Educational
- Released
- 2026-05-09
- 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 Royal Kathey
Habit Formation for CaregiversRoyal Kathey$11.99
Alcohol Free Socializing CourseRoyal Kathey$11.99
Nobel Laureates In Black HolesRoyal Kathey$11.99
Walking Meditation for AsthmaRoyal Kathey$11.99
Channel Positioning MatrixRoyal Kathey$11.99
The Fire Calculators: How Prehistoric Mathematicians Tamed the VolcanoRoyal Kathey$11.99
Nefertiti's Forbidden Flame: The Sun King and the Queen Who Defied the GodsRoyal Kathey$11.99
Understanding Groll–hirschowitz SyndromeRoyal Kathey$17.99
BPO Omnichannel SupportRoyal Kathey$12.99
Payment Processor Account Setup ManualRoyal Kathey$12.99
How to Become a Tile FinisherRoyal Kathey$11.99