SQL for business analysts: check requirements against real data

As a business analyst you rarely build the final report, but you need to know whether the data can support a requirement. A few queries let you check that yourself instead of waiting for an export. Here are five typical BA tasks, each with an example and an exercise.

In short: for business analysis, SELECT, WHERE, GROUP BY, CASE and JOIN usually cover it, which is levels 1 to 3 of the course. With them you see which values are really in a table, how many fields are empty, what a KPI comes to under each definition and which records are missing between two systems.

What business analysts use SQL for

TaskTypical questionSQL for itLesson
Check a requirementDoes the field the business wants in the report exist? Which values does it hold?DISTINCT, GROUP BY with COUNTDISTINCT, GROUP BY
Profile the dataHow many rows, how many empty fields, which date range?COUNT(*), COUNT(column), MIN, MAXCOUNT, NULL
Define a KPIWhat exactly counts as revenue, an active customer, a cancellation?SUM with CASE WHENCASE WHEN, aggregate functions
Reconcile systemsWhich customers in the CRM are missing from accounting?LEFT JOIN with IS NULL, NOT EXISTSLEFT JOIN, EXISTS
Measure data qualityAre customers duplicated? Are required fields missing?GROUP BY with HAVING COUNT(*) > 1find duplicates, HAVING

Example 1: look at the data before you ask questions

Before you write a requirement, a quick profile of the table pays off. One query shows how many rows there are, whether the key is unique, how often a field is filled in and which period the data covers. The example uses the customers table of the practice database, an online office supplies shop:

SELECT COUNT(*) AS row_count,
       COUNT(DISTINCT customer_id) AS customer_ids,
       COUNT(phone) AS with_phone,
       COUNT(DISTINCT city) AS cities,
       MIN(customer_since) AS earliest,
       MAX(customer_since) AS latest
FROM customers;
row_countcustomer_idswith_phonecitiesearliestlatest
1212992020-06-122025-05-30

What it tells you: every customer ID appears once. Three of twelve customers have no phone number, because COUNT(phone) only counts filled-in fields. If sales asks for a call list of all customers, that is a question for the spec: what happens to the three without a number? Finding gaps like this early saves a round trip with the developers later.

Example 2: which values really exist?

Requirements often say "all completed orders". A grouping shows which statuses are actually in the data:

SELECT status, COUNT(*) AS orders
FROM orders
GROUP BY status
ORDER BY orders DESC, status;
statusorders
delivered11
open3
cancelled2
shipped2

Four statuses, and "completed" is not one of them. Whether "shipped" counts is for the business to decide, not the query. Write the answer into the requirement as a list of values, and there won't be two readings later.

Example 3: one KPI, three numbers

"Revenue" sounds clear. With CASE WHEN inside the sum you can put three common definitions side by side in one query:

SELECT ROUND(SUM(i.quantity * i.unit_price), 2) AS all_orders,
       ROUND(SUM(CASE WHEN o.status <> 'cancelled'
                      THEN i.quantity * i.unit_price END), 2) AS excl_cancelled,
       ROUND(SUM(CASE WHEN o.status = 'delivered'
                      THEN i.quantity * i.unit_price END), 2) AS delivered_only
FROM orders AS o
JOIN order_items AS i ON i.order_id = o.order_id;
all_ordersexcl_cancelleddelivered_only
9782.119054.116720.2

The largest and the smallest number are just over 3,000 apart, almost a third. If the spec only says "revenue", you get one of these three numbers depending on who builds the query. A good KPI definition therefore names the table, the filter and the calculation. Practise it on the headline numbers for a year:

Task Management wants the headline numbers for the year in a single row. Include every order that isn't cancelled and show: orders (count), revenue (sum of amount, rounded to 2 decimals), avg_order_value (average amount per order, rounded to 2 decimals) and customers (number of different customers who ordered).

orders 122 rows, 5 columns
order_idcustomer_idorder_datestatusamount
500122025-11-01cancelled93.9
500242025-11-02delivered238.8
500362025-11-08delivered14.9
500432025-11-10delivered29.9
500572025-11-11delivered44.9
500652025-11-13delivered104.7
5007112025-11-16delivered17.9
5008132025-11-17delivered119
500992025-11-18delivered206.8
5010102025-11-20delivered758
5011122025-11-23delivered44.9
501212025-11-25delivered77.8
501342025-11-27delivered149
501482025-11-28delivered39.9
5015102025-12-15delivered777.9
5016142025-12-16delivered55.8
501722025-12-22delivered34.9
5018162025-12-22delivered79
5019152025-12-29delivered22.9
5020202025-12-29delivered59.8
5021212025-12-30delivered379
5022192025-12-31delivered114.7
5023172026-01-03delivered49.8
5024182026-01-08delivered79
502562026-01-14delivered44.9
5026112026-01-16delivered12.9
502792026-01-17delivered49.9
502822026-01-21delivered59.9
5029222026-01-24delivered49.9
5030242026-01-25delivered498
5031252026-02-04delivered413.9
503252026-02-05delivered34.9
5033282026-02-06cancelled34.9
5034262026-02-11delivered17.9
5035112026-02-20delivered39.9
5036212026-02-23delivered170.9
5037292026-02-25delivered49.9
5038272026-02-26delivered24.9
5039122026-03-03delivered308
5040182026-03-03delivered26.9
5041152026-03-06delivered99.6
504212026-03-07delivered403.8
5043312026-03-11delivered417.7
5044302026-03-12delivered149
5045332026-03-13delivered158
5046342026-03-19delivered189
5047322026-03-27delivered123.8
5048352026-03-30delivered93.9
5049192026-04-01delivered69.8
505022026-04-04cancelled368.9
5051342026-04-06delivered47.8
5052202026-04-16delivered119
505362026-04-22delivered258.7
505422026-04-23cancelled126.7
5055112026-04-24delivered29.9
5056362026-04-26delivered79
5057372026-04-26cancelled12.9
5058392026-04-27delivered117.7
5059382026-04-29delivered19.9
5060222026-04-30delivered59.9
5061992026-05-01delivered63.7
5062402026-05-04delivered158
5063412026-05-05delivered378
5064292026-05-14delivered228.7
5065432026-05-17delivered74.7
5066452026-05-25cancelled39.9
5067442026-05-27delivered69.8
5068462026-05-31delivered80.7
5069272026-06-04delivered97.7
5070312026-06-09delivered68.7
5071182026-06-10delivered189
5072192026-06-11delivered57.7
5073352026-06-13delivered149
5074472026-06-19delivered119
5075492026-06-20delivered39.9
5076482026-06-23delivered49.9
5077422026-06-25delivered19.9
5078512026-06-27delivered34.9
5079392026-07-01delivered59.7
5080502026-07-01delivered25.8
5081452026-07-02delivered188.8
5082192026-07-04delivered134.4
5083532026-07-12delivered83.7
5084522026-07-14delivered77.8
5085382026-07-15delivered129.7
5086542026-07-15delivered418.8
5087462026-07-17delivered59.8
5088292026-07-19delivered188.9
5089362026-07-19delivered124.7
5090452026-07-27delivered14.9
5091412026-07-29delivered19.9
5092582026-08-01delivered99.8
5093562026-08-05delivered74.7
5094532026-08-06delivered98.9
5095592026-08-07delivered22.9
5096182026-08-12delivered1157
5097612026-08-16delivered44.7
5098292026-08-20delivered105.7
5099602026-08-24delivered307
5100392026-08-27delivered103.9
5101442026-08-28delivered243.8
5102312026-08-31delivered128.9
5103542026-08-31delivered298
5104422026-09-01delivered388.9
5105472026-09-01delivered124.7
5106632026-09-06cancelled14.9
5107642026-09-06delivered62.8
5108652026-09-06cancelled208.6
5109622026-09-11delivered34.9
5110272026-09-18delivered29.9
5111422026-09-20delivered104.7
5112412026-09-21delivered24.9
5113462026-09-27delivered94.6
5114662026-09-28delivered29.9
5115672026-10-01delivered34.9
5116512026-10-07delivered69.8
5117532026-10-07cancelled34.9
5118702026-10-09delivered211.9
5119642026-10-16delivered698
5120682026-10-21delivered183.9
5121692026-10-27shipped159.4
5122272026-10-30shipped118.9

Example 4: reconcile two systems

A common project task: which records exist in one system but not in the other? Customers with no orders, orders with no invoice, employees with no cost center. The pattern is always the same: a LEFT JOIN that keeps every row of the first table, and a filter on the rows where nothing was found on the right:

SELECT c.customer_id, c.name
FROM customers AS c
LEFT JOIN orders AS o ON o.customer_id = c.customer_id
WHERE o.order_id IS NULL;

In the practice database every customer has ordered at least once, so the result is empty. That is an answer too, and it belongs in the spec. When the data lives in two separate systems, it usually ends up in a shared database or a data warehouse first. Then the key question is which key you join on, for example the customer number from the CRM and the account number from accounting. In the exercise two new customers without orders have been added, and the list should show every customer:

Task Two new customers have signed up but haven't ordered anything yet. Management still wants every customer on the list: name from customers, plus order_id and order_date of each of their orders. Customers with no orders should appear with empty fields.

customers 14 rows, 7 columns
customer_idnamecitycountrycustomer_sincesegmentphone
1Harbor Fremont PartnersBostonUSA2021-03-15Business617-555-0142
2Emily CarterChicagoUSA2022-07-01ConsumerNULL
3Riverside County OfficeRiversideUSA2020-11-20Government951-555-0110
4Raj PatelLeedsUK2023-01-09Consumer0113 496 0123
5Lakeview Hotel LtdManchesterUK2022-04-18Business0161 496 0456
6Olivia BrooksAustinUSA2024-02-27ConsumerNULL
7Greene & Shaw LLPLondonUK2021-09-05Business020 7946 0321
8Maple Grove High SchoolAustinUSA2023-08-14School512-555-0187
9Chloe EvansBostonUSA2025-05-30Consumer617-555-0199
10Northline Printing CoTorontoCanada2020-06-12Business416-555-0133
11Daniel KimSeattleUSA2024-10-03ConsumerNULL
12Westbrook Dental ClinicChicagoUSA2022-12-01Business312-555-0164
15Harlow Street BakeryGlasgowUK2026-06-08Business0141 496 0574
16Jordan EllisPortlandUSA2026-06-11ConsumerNULL
orders 18 rows, 5 columns
order_idcustomer_idorder_datestatusemployee_id
100112026-01-08delivered3
100242026-01-12delivered4
100332026-01-20delivered3
100472026-02-03delivered4
100522026-02-11cancelled8
100612026-02-25delivered3
1007102026-03-04delivered2
100852026-03-17delivered4
100982026-03-30delivered3
101062026-04-07delivered8
1011122026-04-22delivered4
101232026-05-06delivered3
101392026-05-19cancelled8
101472026-06-02shipped4
101512026-06-10shipped3
1016112026-06-12openNULL
101742026-06-13openNULL
1018102026-06-14openNULL

Example 5: measure data quality instead of guessing

"The data is bad" doesn't help a project. "37 customers are duplicated, 12 percent have no email" does, because you can estimate the effort from it. You find duplicates with GROUP BY and HAVING COUNT(*) > 1. Often you have to standardize the values first, for example trim spaces and convert everything to lower case:

Task Before the analysis you check the customers table for duplicates. Two entries count as the same person if their email address is identical once leading and trailing spaces are removed and it is in lower case. Show email (in that cleaned form) and occurrences for every address that appears more than once.

customers 70 rows, 6 columns
customer_idnameemailcitysignup_datechannel
1Samuel Wardsamuel.ward@example.comAustin2025-10-07Newsletter
2Owen Robinsonowen.robinson@example.comDenver2025-08-02Referral
3Liam Martinliam.martin@example.comChicago2025-09-17Search
4Thomas Hughesthomas.hughes@example.comBristol2025-09-07Search
5Chloe Lewischloe.lewis@example.comBristol2025-09-03Newsletter
6Connor Hallconnor.hall@example.comNew York2025-07-07Referral
7Lily Robinsonlily.robinson@example.comGlasgow2025-07-31Newsletter
8James Thomasjames.thomas@example.comGlasgow2025-07-02Search
9Aisha Greenaisha.green@example.comChicago2025-07-16Newsletter
10Sophia Murphysophia.murphy@example.comBirmingham2025-08-03Search
11Emily Harrisemily.harris@example.comLeeds2025-11-08Search
12Hannah Thomashannah.thomas@example.comNULL2025-11-16Search
13Ethan Hallethan.hall@example.comAustin2025-11-13Search
14Lucas Pricelucas.price@example.comLeeds2025-11-26Newsletter
15Priya Harrispriya.harris@example.comNew York2025-12-05Newsletter
16Lucas Reedlucas.reed@example.comSeattle2025-12-01Search
17Fiona Campbellfiona.campbell@example.comDenver2025-12-11Search
18Ryan Wrightryan.wright@example.comChicago2025-12-14Social media
19Priya Evanspriya.evans@example.comDenver2025-12-26Search
20Grace Campbellgrace.campbell@example.comDenver2025-12-26Search
21Aisha Priceaisha.price@example.comNew York2025-12-30Referral
22Zoe Harriszoe.harris@example.comNew York2026-01-11Newsletter
23Liam Brownliam.brown@example.comManchester2026-01-15Newsletter
24Olivia Taylorolivia.taylor@example.comDenver2026-02-03Search
25Aisha Wilsonaisha.wilson@example.comAustin2026-02-13Search
26Megan Reedmegan.reed@example.comGlasgow2026-01-28Search
27Amelia GreenNULLBristol2026-02-04Search
28Kevin Wilsonkevin.wilson@example.comBirmingham2026-02-06Search
29Isla Morganisla.morgan@example.comLondon2026-02-11Search
30Liam Hallliam.hall@example.comBristol2026-02-22Referral
31Zoe Turnerzoe.turner@example.comBirmingham2026-02-24Search
32Daniel Evansdaniel.evans@example.comChicago2026-03-05Newsletter
33Emily Wrightemily.wright@example.comLondon2026-03-07Search
34Connor Taylorconnor.taylor@example.comSeattle2026-03-11Search
35Olivia Reedolivia.reed@example.comNew York2026-03-24Social media
36Kevin Martinkevin.martin@example.comBirmingham2026-04-01Referral
37Emily Daviesemily.davies@example.comAustin2026-04-09Search
38Ruby Johnsonruby.johnson@example.comNULL2026-04-08Social media
39Henry Campbellhenry.campbell@example.comGlasgow2026-04-10Newsletter
40Ethan Murphyethan.murphy@example.comBristol2026-04-24Newsletter
41Ethan Martinethan.martin@example.comManchester2026-05-01Referral
42Liam Campbellliam.campbell@example.comAustin2026-04-30Search
43Holly Harrisholly.harris@example.comNew York2026-05-10Search
44Aaron Smithaaron.smith@example.comManchester2026-05-13Newsletter
45Aisha Bakeraisha.baker@example.comDenver2026-05-19Social media
46Isla Bennettisla.bennett@example.comGlasgow2026-05-18Social media
47Chloe Davieschloe.davies@example.comLeeds2026-06-05Newsletter
48Thomas Robinsonthomas.robinson@example.comBoston2026-06-03Search
49Marcus Evansmarcus.evans@example.comManchester2026-06-15Newsletter
50Oliver Wrightoliver.wright@example.comBristol2026-06-10Search
51Thomas Johnsonthomas.johnson@example.comGlasgow2026-06-18Search
52Sophia Reedsophia.reed@example.comLondon2026-06-24Search
53Fiona Clarkefiona.clarke@example.comLeeds2026-07-02Referral
54Liam HallLIAM.HALL@EXAMPLE.COMBristol2026-07-08Search
55Lily Thomaslily.thomas@example.comBoston2026-07-14Search
56Chloe Robinsonchloe.robinson@example.comBristol2026-07-26Search
57Hannah Campbellhannah.campbell@example.comBoston2026-07-20Social media
58Ruby Morganruby.morgan@example.comNew York2026-07-29Search
59Sophia Smithsophia.smith@example.comLondon2026-07-31Newsletter
60Ava Martinava.martin@example.comBirmingham2026-08-11Social media
61Jack Halljack.hall@example.comNULL2026-08-13Newsletter
62Grace Coopergrace.cooper@example.comChicago2026-08-25Search
63Connor Priceconnor.price@example.comManchester2026-08-23Search
64Marcus Walkermarcus.walker@example.comBristol2026-09-04Social media
65Holly Brownholly.brown@example.comDenver2026-09-06Search
66Priya EvansPriya.Evans@example.com Denver2026-09-19Search
67Carlos Garciacarlos.garcia@example.comChicago2026-09-19Social media
68Priya Thomaspriya.thomas@example.comBristol2026-09-29Search
69Mia Reedmia.reed@example.comChicago2026-10-02Search
70Marcus Turnermarcus.turner@example.comBoston2026-10-04Newsletter

More checks, such as whether an order's amount matches the sum of its lines or whether orders point to customers that don't exist, are in the data quality case of the intensive course.

What business analysts don't need

Creating tables, granting permissions, tuning queries for speed: in most teams that is done by developers or database administrators. More important is reading SQL that others wrote, such as the query behind a report that suddenly shows different numbers. It helps to know the order in which the database runs a query: FROM and JOIN first, then WHERE, GROUP BY, HAVING, and SELECT and ORDER BY last.

Your path through the course

  1. Level 1, getting started (free): SELECT, WHERE, NULL, ORDER BY, DISTINCT. Enough to profile a table and check values.
  2. Level 2, summarizing: COUNT, SUM, GROUP BY, HAVING, CASE, dates. The core for KPIs.
  3. Level 3, joining tables: JOIN, LEFT JOIN, subqueries and EXISTS. This is how you reconcile tables.
  4. Level 5, if you want to show trends over time: CTEs, window functions, month-over-month comparisons. You don't need level 4 (changing data) for this.

After that, the SQL for data analysts intensive course continues with six cases: a KPI overview, an order funnel, ABC analysis, time series, cohorts and data quality, with its own certificate. More on the building blocks of analysis is on SQL for data analysis. If you come from Excel, SQL for Excel users shows the familiar ideas: VLOOKUP becomes JOIN, a PivotTable becomes GROUP BY. And for the Excel side of the job there is Excel for data analysis.

FAQ

Do business analysts need SQL?

Not every role asks for it; the job ad will tell you. If you know it, you can check requirements against the data yourself, spot gaps sooner and talk to developers on equal terms. For most tasks, levels 1 to 3 of the course are enough.

How does SQL differ for a business analyst and a data analyst?

The commands are the same, the purpose is different. A data analyst builds analyses and reports, often with window functions and long queries. A business analyst uses SQL more to check requirements, understand the data and pin down KPIs. For data analysts there is SQL for data analysis.

Which database should I learn?

The one your company uses, if you know it. Otherwise learn the basics, which are almost the same in MySQL, PostgreSQL, SQL Server and SQLite. Our exercises run on SQLite, and you can switch the model answer to MySQL, PostgreSQL or SQL Server.

Do I need to install anything?

No. All exercises run in your browser against a real database on the server. The results on this page come from exactly that database.

Can I prove my SQL skills?

Yes. After the course's final test you get an SQL certificate with a verification link, and the intensive course has its own data analysis certificate.

Write your first query

Level 1 is free. After it, you can profile your first table yourself.

Go to the SQL course Data analysis intensive course

Write to us

Choose language

Select your preferred language