sign up today

Ready to Go Pro with Maven Analytics

Ready to Go Pro with Maven Analytics

Sign up today an unlock full access to all data and AI learning content.

free email course

SQL with AI

Day 1

Beginner

free email course

SQL with AI

Day 1

Beginner

The Brief

Why this SQL course is different from any other SQL course you’ve taken before

Before we jump into the analyst brief, let me walk you through the three guiding principles that will be the foundations of every email that you get from me:

  1. SQL + AI beats SQL alone. Not because AI writes the queries for you, but because AI cuts the learning curve, helps you interpret results and error messages, and handles the communication layer so you can move faster and deliver more.

  2. Implementation over memorization. The goal is never to recite syntax from memory. The goal is to answer a business question accurately and quickly, using every tool available.

  3. The last 10% is yours. AI can generate 90% of a query, fast. The analyst who actually understands the data, can validate the results, and translate the work to insights and drive business outcomes is still irreplaceable.

The scenario

You've just joined the Apex Retail data team. Your manager, Sarah (Head of Commerce), has one request:

"Leadership needs a Q1 sales review on Friday. I need to know what's going on with the business."

That brief is deliberately vague, real analyst briefs usually are. Your job over the next 5 days is to go from that question to a clear, data-backed story. Today you start by understanding what you're working with.

Environment Setup

Go to onecompiler.com/mysql. Free, no sign-up, runs MySQL, the same dialect as Maven's SQL courses. You'll use this all week.

Don’t worry if there are already some queries in the editor as you open it up. Just select everything and hit Delete on your keyboard.

Paste the dataset below into the editor and click RUN at the top right. That's your working database for the week.

CREATE TABLE orders (
  order_id      INT,
  order_date    DATE,
  customer_name VARCHAR(100),
  city          VARCHAR(50),
  country       VARCHAR(3),
  category      VARCHAR(50),
  product       VARCHAR(100),
  quantity      INT,
  unit_price    DECIMAL(10,2),
  discount_pct  DECIMAL(4,2),
  revenue       DECIMAL(10,2)
);

INSERT INTO orders VALUES
(1001, '2024-01-08', 'Sarah Mitchell',   'London',      'GBR', 'Laptops',     'ProBook 14',          1, 899.00, 0.00,  899.00),
(1002, '2024-01-10', 'James Cooper',     'New York',    'USA', 'Accessories', 'USB-C Hub 7-Port',    2,  49.99, 0.10,   89.98),
(1003, '2024-01-12', 'Aisha Okafor',     'Lagos',       'NGA', 'Monitors',    '27" 4K Display',      1, 449.00, 0.00,  449.00),
(1004, '2024-01-15', 'Lucas Ferreira',   'São Paulo',   'BRA', 'Peripherals', 'Mechanical Keyboard', 1, 129.00, 0.05,  122.55),
(1005, '2024-01-17', 'Emma Johansson',   'Stockholm',   'SWE', 'Software',    'Analytics Suite Pro', 1, 299.00, 0.00,  299.00),
(1006, '2024-01-20', 'Oliver Wright',    'Manchester',  'GBR', 'Accessories', 'USB-C Hub 7-Port',    3,  49.99, 0.15,  127.47),
(1007, '2024-01-22', 'Priya Sharma',     'Mumbai',      'IND', 'Laptops',     'UltraSlim 13',        1, 749.00, 0.05,  711.55),
(1008, '2024-01-25', 'Noah Müller',      'Berlin',      'DEU', 'Monitors',    '24" FHD Monitor',     2, 249.00, 0.00,  498.00),
(1009, '2024-01-28', 'Isabella Rossi',   'Milan',       'ITA', 'Peripherals', 'Wireless Mouse',      1,  59.99, 0.00,   59.99),
(1010, '2024-01-30', 'Liam Nguyen',      'Ho Chi Minh', 'VNM', 'Software',    'Analytics Suite Pro', 2, 299.00, 0.10,  538.20),
(1011, '2024-02-02', 'Charlotte Brown',  'Sydney',      'AUS', 'Laptops',     'ProBook 14',          1, 899.00, 0.00,  899.00),
(1012, '2024-02-05', 'Ethan Davis',      'Toronto',     'CAN', 'Accessories', 'Laptop Stand Adj.',   2,  39.99, 0.00,   79.98),
(1013, '2024-02-08', 'Mia Wilson',       'Paris',       'FRA', 'Monitors',    '27" 4K Display',      1, 449.00, 0.05,  426.55),
(1014, '2024-02-10', 'Henry Thompson',   'London',      'GBR', 'Peripherals', 'Mechanical Keyboard', 2, 129.00, 0.10,  232.20),
(1015, '2024-02-12', 'Amara Diallo',     'Dakar',       'SEN', 'Software',    'Data Viz Toolkit',    1, 149.00, 0.00,  149.00),
(1016, '2024-02-15', 'Jack Martinez',    'Mexico City', 'MEX', 'Accessories', 'USB-C Hub 7-Port',    1,  49.99, 0.00,   49.99),
(1017, '2024-02-18', 'Sophie Taylor',    'Edinburgh',   'GBR', 'Laptops',     'UltraSlim 13',        1, 749.00, 0.00,  749.00),
(1018, '2024-02-20', 'Daniel Kim',       'Seoul',       'KOR', 'Monitors',    '32" Curved QHD',      1, 599.00, 0.10,  539.10),
(1019, '2024-02-22', 'Grace O''Brien',   'Dublin',      'IRL', 'Peripherals', 'Wireless Mouse',      3,  59.99, 0.15,  152.97),
(1020, '2024-02-25', 'Alex Chen',        'Singapore',   'SGP', 'Software',    'Analytics Suite Pro', 1, 299.00, 0.00,  299.00),
(1021, '2024-03-01', 'Rachel Adams',     'Chicago',     'USA', 'Laptops',     'ProBook 14',          2, 899.00, 0.10, 1618.20),
(1022, '2024-03-04', 'Ben Patel',        'Birmingham',  'GBR', 'Accessories', 'Laptop Stand Adj.',   1,  39.99, 0.00,   39.99),
(1023, '2024-03-07', 'Fatima Al-Rashid', 'Dubai',       'ARE', 'Monitors',    '27" 4K Display',      2, 449.00, 0.05,  853.10),
(1024, '2024-03-10', 'Tom Reilly',       'Dublin',      'IRL', 'Software',    'Data Viz Toolkit',    2, 149.00, 0.10,  268.20),
(1025, '2024-03-12', 'Chloe Dubois',     'Lyon',        'FRA', 'Peripherals', 'Mechanical Keyboard', 1, 129.00, 0.00,  129.00),
(1026, '2024-03-15', 'Marcus Johnson',   'Atlanta',     'USA', 'Laptops',     'UltraSlim 13',        1, 749.00, 0.05,  711.55),
(1027, '2024-03-18', 'Elena Petrova',    'Moscow',      'RUS', 'Accessories', 'USB-C Hub 7-Port',    4,  49.99, 0.20,  159.97),
(1028, '2024-03-20', 'Wei Zhang',        'Shanghai',    'CHN', 'Monitors',    '32" Curved QHD',      2, 599.00, 0.00, 1198.00),
(1029, '2024-03-25', 'Ava Robinson',     'Melbourne',   'AUS', 'Software',    'Analytics Suite Pro', 3, 299.00, 0.10,  807.30),
(1030, '2024-03-28', 'Sam Fletcher',     'Leeds',       'GBR', 'Peripherals', 'Wireless Mouse',      2,  59.99, 0.05,  113.98)

CREATE TABLE orders (
  order_id      INT,
  order_date    DATE,
  customer_name VARCHAR(100),
  city          VARCHAR(50),
  country       VARCHAR(3),
  category      VARCHAR(50),
  product       VARCHAR(100),
  quantity      INT,
  unit_price    DECIMAL(10,2),
  discount_pct  DECIMAL(4,2),
  revenue       DECIMAL(10,2)
);

INSERT INTO orders VALUES
(1001, '2024-01-08', 'Sarah Mitchell',   'London',      'GBR', 'Laptops',     'ProBook 14',          1, 899.00, 0.00,  899.00),
(1002, '2024-01-10', 'James Cooper',     'New York',    'USA', 'Accessories', 'USB-C Hub 7-Port',    2,  49.99, 0.10,   89.98),
(1003, '2024-01-12', 'Aisha Okafor',     'Lagos',       'NGA', 'Monitors',    '27" 4K Display',      1, 449.00, 0.00,  449.00),
(1004, '2024-01-15', 'Lucas Ferreira',   'São Paulo',   'BRA', 'Peripherals', 'Mechanical Keyboard', 1, 129.00, 0.05,  122.55),
(1005, '2024-01-17', 'Emma Johansson',   'Stockholm',   'SWE', 'Software',    'Analytics Suite Pro', 1, 299.00, 0.00,  299.00),
(1006, '2024-01-20', 'Oliver Wright',    'Manchester',  'GBR', 'Accessories', 'USB-C Hub 7-Port',    3,  49.99, 0.15,  127.47),
(1007, '2024-01-22', 'Priya Sharma',     'Mumbai',      'IND', 'Laptops',     'UltraSlim 13',        1, 749.00, 0.05,  711.55),
(1008, '2024-01-25', 'Noah Müller',      'Berlin',      'DEU', 'Monitors',    '24" FHD Monitor',     2, 249.00, 0.00,  498.00),
(1009, '2024-01-28', 'Isabella Rossi',   'Milan',       'ITA', 'Peripherals', 'Wireless Mouse',      1,  59.99, 0.00,   59.99),
(1010, '2024-01-30', 'Liam Nguyen',      'Ho Chi Minh', 'VNM', 'Software',    'Analytics Suite Pro', 2, 299.00, 0.10,  538.20),
(1011, '2024-02-02', 'Charlotte Brown',  'Sydney',      'AUS', 'Laptops',     'ProBook 14',          1, 899.00, 0.00,  899.00),
(1012, '2024-02-05', 'Ethan Davis',      'Toronto',     'CAN', 'Accessories', 'Laptop Stand Adj.',   2,  39.99, 0.00,   79.98),
(1013, '2024-02-08', 'Mia Wilson',       'Paris',       'FRA', 'Monitors',    '27" 4K Display',      1, 449.00, 0.05,  426.55),
(1014, '2024-02-10', 'Henry Thompson',   'London',      'GBR', 'Peripherals', 'Mechanical Keyboard', 2, 129.00, 0.10,  232.20),
(1015, '2024-02-12', 'Amara Diallo',     'Dakar',       'SEN', 'Software',    'Data Viz Toolkit',    1, 149.00, 0.00,  149.00),
(1016, '2024-02-15', 'Jack Martinez',    'Mexico City', 'MEX', 'Accessories', 'USB-C Hub 7-Port',    1,  49.99, 0.00,   49.99),
(1017, '2024-02-18', 'Sophie Taylor',    'Edinburgh',   'GBR', 'Laptops',     'UltraSlim 13',        1, 749.00, 0.00,  749.00),
(1018, '2024-02-20', 'Daniel Kim',       'Seoul',       'KOR', 'Monitors',    '32" Curved QHD',      1, 599.00, 0.10,  539.10),
(1019, '2024-02-22', 'Grace O''Brien',   'Dublin',      'IRL', 'Peripherals', 'Wireless Mouse',      3,  59.99, 0.15,  152.97),
(1020, '2024-02-25', 'Alex Chen',        'Singapore',   'SGP', 'Software',    'Analytics Suite Pro', 1, 299.00, 0.00,  299.00),
(1021, '2024-03-01', 'Rachel Adams',     'Chicago',     'USA', 'Laptops',     'ProBook 14',          2, 899.00, 0.10, 1618.20),
(1022, '2024-03-04', 'Ben Patel',        'Birmingham',  'GBR', 'Accessories', 'Laptop Stand Adj.',   1,  39.99, 0.00,   39.99),
(1023, '2024-03-07', 'Fatima Al-Rashid', 'Dubai',       'ARE', 'Monitors',    '27" 4K Display',      2, 449.00, 0.05,  853.10),
(1024, '2024-03-10', 'Tom Reilly',       'Dublin',      'IRL', 'Software',    'Data Viz Toolkit',    2, 149.00, 0.10,  268.20),
(1025, '2024-03-12', 'Chloe Dubois',     'Lyon',        'FRA', 'Peripherals', 'Mechanical Keyboard', 1, 129.00, 0.00,  129.00),
(1026, '2024-03-15', 'Marcus Johnson',   'Atlanta',     'USA', 'Laptops',     'UltraSlim 13',        1, 749.00, 0.05,  711.55),
(1027, '2024-03-18', 'Elena Petrova',    'Moscow',      'RUS', 'Accessories', 'USB-C Hub 7-Port',    4,  49.99, 0.20,  159.97),
(1028, '2024-03-20', 'Wei Zhang',        'Shanghai',    'CHN', 'Monitors',    '32" Curved QHD',      2, 599.00, 0.00, 1198.00),
(1029, '2024-03-25', 'Ava Robinson',     'Melbourne',   'AUS', 'Software',    'Analytics Suite Pro', 3, 299.00, 0.10,  807.30),
(1030, '2024-03-28', 'Sam Fletcher',     'Leeds',       'GBR', 'Peripherals', 'Wireless Mouse',      2,  59.99, 0.05,  113.98)

CREATE TABLE orders (
  order_id      INT,
  order_date    DATE,
  customer_name VARCHAR(100),
  city          VARCHAR(50),
  country       VARCHAR(3),
  category      VARCHAR(50),
  product       VARCHAR(100),
  quantity      INT,
  unit_price    DECIMAL(10,2),
  discount_pct  DECIMAL(4,2),
  revenue       DECIMAL(10,2)
);

INSERT INTO orders VALUES
(1001, '2024-01-08', 'Sarah Mitchell',   'London',      'GBR', 'Laptops',     'ProBook 14',          1, 899.00, 0.00,  899.00),
(1002, '2024-01-10', 'James Cooper',     'New York',    'USA', 'Accessories', 'USB-C Hub 7-Port',    2,  49.99, 0.10,   89.98),
(1003, '2024-01-12', 'Aisha Okafor',     'Lagos',       'NGA', 'Monitors',    '27" 4K Display',      1, 449.00, 0.00,  449.00),
(1004, '2024-01-15', 'Lucas Ferreira',   'São Paulo',   'BRA', 'Peripherals', 'Mechanical Keyboard', 1, 129.00, 0.05,  122.55),
(1005, '2024-01-17', 'Emma Johansson',   'Stockholm',   'SWE', 'Software',    'Analytics Suite Pro', 1, 299.00, 0.00,  299.00),
(1006, '2024-01-20', 'Oliver Wright',    'Manchester',  'GBR', 'Accessories', 'USB-C Hub 7-Port',    3,  49.99, 0.15,  127.47),
(1007, '2024-01-22', 'Priya Sharma',     'Mumbai',      'IND', 'Laptops',     'UltraSlim 13',        1, 749.00, 0.05,  711.55),
(1008, '2024-01-25', 'Noah Müller',      'Berlin',      'DEU', 'Monitors',    '24" FHD Monitor',     2, 249.00, 0.00,  498.00),
(1009, '2024-01-28', 'Isabella Rossi',   'Milan',       'ITA', 'Peripherals', 'Wireless Mouse',      1,  59.99, 0.00,   59.99),
(1010, '2024-01-30', 'Liam Nguyen',      'Ho Chi Minh', 'VNM', 'Software',    'Analytics Suite Pro', 2, 299.00, 0.10,  538.20),
(1011, '2024-02-02', 'Charlotte Brown',  'Sydney',      'AUS', 'Laptops',     'ProBook 14',          1, 899.00, 0.00,  899.00),
(1012, '2024-02-05', 'Ethan Davis',      'Toronto',     'CAN', 'Accessories', 'Laptop Stand Adj.',   2,  39.99, 0.00,   79.98),
(1013, '2024-02-08', 'Mia Wilson',       'Paris',       'FRA', 'Monitors',    '27" 4K Display',      1, 449.00, 0.05,  426.55),
(1014, '2024-02-10', 'Henry Thompson',   'London',      'GBR', 'Peripherals', 'Mechanical Keyboard', 2, 129.00, 0.10,  232.20),
(1015, '2024-02-12', 'Amara Diallo',     'Dakar',       'SEN', 'Software',    'Data Viz Toolkit',    1, 149.00, 0.00,  149.00),
(1016, '2024-02-15', 'Jack Martinez',    'Mexico City', 'MEX', 'Accessories', 'USB-C Hub 7-Port',    1,  49.99, 0.00,   49.99),
(1017, '2024-02-18', 'Sophie Taylor',    'Edinburgh',   'GBR', 'Laptops',     'UltraSlim 13',        1, 749.00, 0.00,  749.00),
(1018, '2024-02-20', 'Daniel Kim',       'Seoul',       'KOR', 'Monitors',    '32" Curved QHD',      1, 599.00, 0.10,  539.10),
(1019, '2024-02-22', 'Grace O''Brien',   'Dublin',      'IRL', 'Peripherals', 'Wireless Mouse',      3,  59.99, 0.15,  152.97),
(1020, '2024-02-25', 'Alex Chen',        'Singapore',   'SGP', 'Software',    'Analytics Suite Pro', 1, 299.00, 0.00,  299.00),
(1021, '2024-03-01', 'Rachel Adams',     'Chicago',     'USA', 'Laptops',     'ProBook 14',          2, 899.00, 0.10, 1618.20),
(1022, '2024-03-04', 'Ben Patel',        'Birmingham',  'GBR', 'Accessories', 'Laptop Stand Adj.',   1,  39.99, 0.00,   39.99),
(1023, '2024-03-07', 'Fatima Al-Rashid', 'Dubai',       'ARE', 'Monitors',    '27" 4K Display',      2, 449.00, 0.05,  853.10),
(1024, '2024-03-10', 'Tom Reilly',       'Dublin',      'IRL', 'Software',    'Data Viz Toolkit',    2, 149.00, 0.10,  268.20),
(1025, '2024-03-12', 'Chloe Dubois',     'Lyon',        'FRA', 'Peripherals', 'Mechanical Keyboard', 1, 129.00, 0.00,  129.00),
(1026, '2024-03-15', 'Marcus Johnson',   'Atlanta',     'USA', 'Laptops',     'UltraSlim 13',        1, 749.00, 0.05,  711.55),
(1027, '2024-03-18', 'Elena Petrova',    'Moscow',      'RUS', 'Accessories', 'USB-C Hub 7-Port',    4,  49.99, 0.20,  159.97),
(1028, '2024-03-20', 'Wei Zhang',        'Shanghai',    'CHN', 'Monitors',    '32" Curved QHD',      2, 599.00, 0.00, 1198.00),
(1029, '2024-03-25', 'Ava Robinson',     'Melbourne',   'AUS', 'Software',    'Analytics Suite Pro', 3, 299.00, 0.10,  807.30),
(1030, '2024-03-28', 'Sam Fletcher',     'Leeds',       'GBR', 'Peripherals', 'Wireless Mouse',      2,  59.99, 0.05,  113.98)

If you get the output below, that’s good. The program didn’t output anything because you haven’t asked it to.

Output: Program did not output anything!

Now run these queries to verify that the information in your table exists and is correct:

SELECT COUNT(*) FROM orders; -- 30 orders in total
SELECT MIN(order_date), MAX(order_date) FROM orders; -- Date range: 2024-01-08 to 2024-03-28
SELECT SUM(revenue) FROM orders; -- Total revenue is $13,270.82
SELECT COUNT(*) FROM orders; -- 30 orders in total
SELECT MIN(order_date), MAX(order_date) FROM orders; -- Date range: 2024-01-08 to 2024-03-28
SELECT SUM(revenue) FROM orders; -- Total revenue is $13,270.82
SELECT COUNT(*) FROM orders; -- 30 orders in total
SELECT MIN(order_date), MAX(order_date) FROM orders; -- Date range: 2024-01-08 to 2024-03-28
SELECT SUM(revenue) FROM orders; -- Total revenue is $13,270.82

You can highlight each separate query (i.e. each row in this case) and hit RUN at the top right or if you prefer shortcuts, just press Control/Command Enter (Control + Enter if you’re on Windows / Command + Enter if you’re on Mac). If you ask me, I like my shortcuts!

Alternatively, you can select all three queries and run them all.

exercise 1

Take your first data snapshot

5 min

Just to reiterate how to run your SQL queries, you need to

  • paste the query into your editor

  • highlight your query

  • hit RUN or use Control/Command + Enter

If you ever do get a little lost, just scroll back up and refer to these steps here or the guidance in Step 0.

Let’s start with this.

SELECT * FROM orders
ORDER BY order_date
LIMIT 10

SELECT * FROM orders
ORDER BY order_date
LIMIT 10

SELECT * FROM orders
ORDER BY order_date
LIMIT 10

You're asking: show me the first 10 orders, chronologically. Scroll through the results. Before you do any analysis, answer these three questions in your head:

  1. What time period does this data cover?

  2. Which columns would matter most to Sarah?

  3. Does anything look unusual in the data?

Now run a proper baseline summary: (we’ve already done a quick sense check before on the total number of rows, minimum and maximum dates, and the total revenue, remember?)

SELECT
  COUNT(*)                    AS total_orders,
  MIN(order_date)             AS period_start,
  MAX(order_date)             AS period_end,
  ROUND(SUM(revenue), 2)      AS total_revenue,
  ROUND(AVG(revenue), 2)      AS avg_order_value
FROM

SELECT
  COUNT(*)                    AS total_orders,
  MIN(order_date)             AS period_start,
  MAX(order_date)             AS period_end,
  ROUND(SUM(revenue), 2)      AS total_revenue,
  ROUND(AVG(revenue), 2)      AS avg_order_value
FROM

SELECT
  COUNT(*)                    AS total_orders,
  MIN(order_date)             AS period_start,
  MAX(order_date)             AS period_end,
  ROUND(SUM(revenue), 2)      AS total_revenue,
  ROUND(AVG(revenue), 2)      AS avg_order_value
FROM

In five lines, you now know: how many orders exist, what period they cover, total revenue, and average order value. This is your baseline. Every other number this week gets measured against it.

The AI move: paste your baseline result into Copilot, Claude, or ChatGPT and ask: "I'm running a Q1 sales review and this is my baseline. What would a Head of Commerce want to understand next, in priority order?" Save the response. You'll use it this week.

Pro Tip: if at any point you do not understand a query, simply ask AI to explain. Use this prompt: “Explain the following SQL query to me step-by-step, like I’m an analyst who’s just started to learn SQL: [your SQL query].

exercise 2

Find out where the business actually lives

5 min

Sarah mentions that the UK is Apex Retail's biggest market. Let's check that assumption.

exercise 3

Write your first analytical filter

5 min

Sarah will almost certainly ask about high-value orders, the ones that move the needle. Let's find them.

Run this to see all orders above $500:

Go Deeper

All resources below are completely FREE Maven Analytics resources; it takes two seconds to create an account and we won’t even ask for your credit card details, I promise! Have a look around.

  1. Data Playground: Here are 68 free datasets that you can download to practice you skills

  2. ChatGPT for Data Analytics: The whole course is free from start to finish. It has a specific chapter on ChatGPT for SQL, but also covers in detail ChatGPT for Excel, Google Sheets, Power BI and Python (just in case you want to learn something else as well)

  3. MySQL for Data Analysis: Great for Analysts or BI professionals looking to quickly retrieve or analyse data stored in relational database systems

Looking forward to Tomorrow

Sarah's first real question. "What's actually driving our revenue?" You'll answer it in three queries, and I'll show you the thinking process that makes the result genuinely useful.

Before you go, don’t forget to:

  • check the answers at the end of this email

  • hold on to this email or save your queries somewhere easily accessible (Google Doc, Word doc, text file, etc) as we will be using the same dataset tomorrow