The loop
Read a question → find the table that holds the fact → look at a few rows → write the query → check the result against the traps → type the answer and press Check → read the explanation → next question → hand in.
All challenges and every certification for $9 a month. And learn to build, buy and guide AI agents for supply chain: https://www.skool.com/supplychain
Planning, customer service and finance send you questions. The answers are in a copy of the company's ERP, warehouse, transport and planning tables. You write SQL to find them, then type each answer in. The hard part is not the SQL: it is knowing which table holds the fact and spotting the numbers that look right but aren't.
These steps get a pass on any Data Detective contract.
Each contract is one database and eight questions from the business. You can run queries and check answers in any order, and hand in once.
Read a question → find the table that holds the fact → look at a few rows → write the query → check the result against the traps → type the answer and press Check → read the explanation → next question → hand in.
Where supply chain data lives (item and supplier masters, stock by location and status, order and PO lines, receipts, shipments, forecasts), what one row of each table means, how keys join tables, and SQL for counts, sums, joins and rates such as on-time-in-full (OTIF) and forecast accuracy.
The database is real-world messy on purpose. Blocked stock, cancelled lines, partial receipts, duplicate suppliers, cases mixed with packs and four versions of every forecast all give a confident wrong number to a query that ignores them.
The Tables panel is on the left, the SQL console on the right, and the questions below them. The briefing column sits on the far left until you hide it.
Every question follows the same chain. Most wrong answers skip step 3.
The small label at the top of each question card says its kind and its points. The kind decides which skill the question trains; for the score only the points matter.
Questions about the data itself: which table or system answers a question, what one row of a table means, or why the data is stored the way it is. Usually a multiple-choice question. It trains Knowing where supply chain data lives in your skill profile; in the score its points count like any other question's.
How to solve it: Read the table descriptions and the grain line in the Tables panel before you answer. You rarely need a query for these.
Find one number in one table, such as the stock of an item. The right table and the right filter are the whole job. It trains Knowing where supply chain data lives in your skill profile; in the score its points count like any other question's.
How to solve it: Run SELECT * on the table with a WHERE on the item first, look at every row, then SUM.
The answer needs two tables linked by a key, for example an item and its supplier, or a PO line and its receipts. It trains Joining and aggregating data correctly in your skill profile; in the score its points count like any other question's.
How to solve it: Open both tables' Columns lists and find the column marked FK. Join on that key, never on a name.
Counts, sums, averages and rates over many rows, often with a date range or a GROUP BY. It trains Joining and aggregating data correctly in your skill profile; in the score its points count like any other question's.
How to solve it: Check the filter before the maths: date range, status and units. Then compute the rate in one query so you don't round twice.
A question with a data-quality catch: blocked stock, cancelled lines, duplicate master records, mixed units or several forecast versions. The obvious query gives a wrong number. It trains Spotting data-quality traps in your skill profile; in the score its points count like any other question's.
How to solve it: Ask what the question really means (sellable, still to arrive, one company). Look at the status and the master data columns before you sum anything.
The console runs SQLite, one read-only query at a time, on a fresh copy of the data. A query can be up to 4,000 characters. Every query below works; the examples use tables from the Sandys Garden Tools contract, so swap in the names from your own Tables panel.
| What you want | SQL that works here | Good to know |
|---|---|---|
| See a table | SELECT * FROM customers LIMIT 20 | Click a table name in the Tables panel to get this query in the console. |
| Filter | SELECT * FROM sales_order_lines WHERE status = 'open' AND qty_ordered > 50 | = compares text exactly, capitals included. Text values go in single quotes. |
| Match part of a text | SELECT * FROM item_master WHERE description LIKE '%hose%' | LIKE ignores capitals; % stands for any text. |
| Count, sum, average | SELECT COUNT(*), SUM(qty_on_hand), AVG(qty_on_hand) FROM inventory_balance | MIN, MAX and TOTAL work too. There is no MEDIAN function. |
| Count different values | SELECT COUNT(DISTINCT customer_id) FROM sales_order_lines | How many customers, items or suppliers appear. |
| Group and filter groups | SELECT customer_id, COUNT(*) FROM sales_order_lines GROUP BY customer_id HAVING COUNT(*) > 10 | HAVING filters after grouping; WHERE filters before. |
| Join two tables | SELECT s.order_id, c.name FROM sales_order_lines s JOIN customers c ON c.customer_id = s.customer_id | Join on the column marked FK in the Columns list. |
| Keep rows with no match | SELECT s.order_id, t.status FROM sales_order_lines s LEFT JOIN shipments t ON t.order_id = s.order_id | Missing matches show as NULL. Test them with IS NULL. |
| Conditional count | SELECT SUM(CASE WHEN qty_shipped < qty_ordered THEN 1 ELSE 0 END) FROM sales_order_lines | IIF(condition, a, b) is a short form of CASE. |
| Dates | SELECT order_id, julianday(promised_date) - julianday(requested_date) AS days FROM sales_order_lines | date(), strftime('%m', d) and date(d, '+7 days') also work. Use the database's "Today is" date, not your own. |
| Step-by-step query | WITH stock AS (SELECT item_id, SUM(qty_on_hand) AS qty FROM inventory_balance GROUP BY item_id) SELECT * FROM stock ORDER BY qty DESC | WITH builds a temporary result you can query again. Ideal for per-line totals. |
| Subquery | SELECT * FROM item_master WHERE item_id IN (SELECT item_id FROM purchase_order_lines WHERE status = 'open') | A query inside a query. |
| Ranking | SELECT item_id, qty_on_hand, RANK() OVER (ORDER BY qty_on_hand DESC) FROM inventory_balance | Window functions such as ROW_NUMBER and RANK work. |
| Rounding and decimals | SELECT ROUND(100.0 * 7 / 9, 1) | Whole numbers divide to a whole number (7 / 9 = 0). Multiply by 100.0 or 1.0 first. |
| Missing values | SELECT COALESCE(qty_shipped, 0) FROM sales_order_lines | IFNULL does the same. |
| Stack results | SELECT 'open', COUNT(*) FROM sales_order_lines WHERE status = 'open' UNION ALL SELECT 'all', COUNT(*) FROM sales_order_lines | Several numbers side by side in one run. |
| Notes in a query | SELECT COUNT(*) FROM customers -- one row per account | Comments with -- or /* */ are fine. |
The chips under the editor insert a template at the cursor. Hover a chip to see what it inserts. Replace table_name, column and the dates with real names.
| Button | Inserts | Use it for |
|---|---|---|
| Count rows | SELECT COUNT(*) FROM table_name WHERE column = 'value' | How many lines, orders or records match a filter. |
| Sum | SELECT SUM(column) FROM table_name WHERE column = 'value' | Total units, value or quantity. |
| Group by | SELECT column, COUNT(*), SUM(other_column) FROM table_name GROUP BY column ORDER BY 2 DESC | A breakdown per status, warehouse or supplier. The best first look at any table. |
| Join | SELECT a.*, b.* FROM table_a a JOIN table_b b ON b.key = a.key LIMIT 20 | Link two tables on their key. |
| Date range | WHERE date_column BETWEEN '2026-07-01' AND '2026-09-30' | Keep one quarter or one period. Dates are text in YYYY-MM-DD form, so BETWEEN works. |
| Distinct | SELECT DISTINCT column FROM table_name | See every value a column takes, such as all statuses. |
| Days between | julianday(later_date) - julianday(earlier_date) | Lead times and days late. The result is a number of days. |
| Case when | SUM(CASE WHEN condition THEN 1 ELSE 0 END) | Count only the rows that meet a condition, inside a bigger query. The heart of every on-time rate. |
Errors show in a red box under the console. A failed query still counts towards your query total, so read the message before you try again.
| Example | Message you see | What to do |
|---|---|---|
| DELETE FROM customers | Only reading is allowed: this database is read-only. | You tried to change data, create a table, use PRAGMA or ATTACH. Only SELECT (and WITH) queries run. |
| SELECT 1; SELECT 2 | SQL error: You can only execute one statement at a time. | Two statements in one run. Run them one by one, or join them with UNION ALL. |
| SELECT * FROM stock | SQL error: no such table: stock | A typo or a table from another contract. Click the table name in the Tables panel instead of typing it. |
| SELECT item FROM item_master | SQL error: no such column: item | Open the table's Columns list and click the column name to insert it. |
| SELECT MEDIAN(qty_on_hand) FROM inventory_balance | SQL error: no such function: MEDIAN | The function doesn't exist in SQLite. Use the ones in the table above. |
| SELECT COUNT(*) FROM inventory_balance a, inventory_balance b, inventory_balance c, inventory_balance d | The query is too heavy and was stopped. Filter earlier, or join on the key columns. | A join with no ON condition multiplies every row by every row. Add the key condition. |
Every contract hides some of these. The briefing's tasks usually name the ones that matter for that database.
Stock tables list every bin and every stock status. Units on hand are not units you can sell: blocked or quarantined lots are on the shelf but not available.
How to avoid it: GROUP BY the status column first to see what statuses exist, then filter on the sellable one.
Order and PO lines stay in the table when they are cancelled. Counting them inflates every total and every rate.
How to avoid it: Add WHERE status <> 'cancelled' (or whatever the status is called) to every count of lines.
One PO line can be delivered in several receipts, and some receipts are short. "Received in full" means the sum of all receipts reaches the ordered quantity; "still to arrive" is ordered minus received on open lines.
How to avoid it: SUM the receipts per line in a WITH block first, then compare with the ordered quantity.
The same supplier or customer can exist twice, for example after a rushed onboarding or a change of address. Names differ slightly; the tax or VAT number is the same.
How to avoid it: GROUP BY the tax or VAT column and look for counts above 1. The newer record has the later creation date.
Some customers order in cases, others in packs. Adding the quantities as they are mixes apples and boxes of apples.
How to avoid it: Join a conversion table on item and unit and multiply by the factor before you sum.
A forecast table can hold one row per target week for every time it was published (the lag). Summing all of them counts the same week four times.
How to avoid it: Filter on the one lag the question asks for, for example lag = 1.
Each question has 2 checks. An empty box is not sent and doesn't use a check; a wrong answer does, even if you typed the same one before.
A text box with the unit next to it. Type the number only: a dot for decimals (12.5), no thousands separator. A € or % sign and spaces are ignored. Most questions need the exact value; some rates, averages and euro values accept a small margin (0.6 of a point or €1 in the current contracts).
How to use it: Use ROUND(x, 1) in the query so you copy what the engine compares. Press Enter in the box to check.
A code or a name, such as a supplier code or an item code. Capitals don't matter, but the spelling must match the database exactly. Where the question says "code or name", either is accepted.
How to use it: Copy the value from the result grid rather than typing it from memory.
Pick one option with the radio buttons, then press Check. Used for landscape questions about where data lives and what a row means.
How to use it: Think about the grain: what one row stands for usually decides the answer.
A question pays its points in full only when the first check is right. A hint costs 30% of the question's points whatever happens next.
| Result | Without hint | With hint (−30%) | What the card shows |
|---|---|---|---|
| Right on the first check | 100% | 70% | Explanation shown |
| Right on the second check | 60% | 42% | Explanation shown |
| Wrong 2 times | 0% | 0% | Right answer and explanation shown |
| Never checked | 0% | 0% | Right answer shown after you hand in |
Everything works with the mouse; two keys save time in the console and the answer boxes.
Your score out of 100 is 85% answers and 15% efficiency. Every point counts the same, whatever kind of question it comes from, so one wrong answer costs about the same in every contract. The projected score in the top bar is the real score of your answers so far, with unanswered questions at zero.
| Part | Weight | What counts |
|---|---|---|
| Answers | 85% | Points earned as a share of all the contract's points. Right first time keeps all of a question's points, right on the second check 60%, and a hint takes 30% off what is left. |
| Getting there with few queries | 15% | Your pace times the share of all points you earned. Pace is 100 while your query count is at or under par, then drops 50 points for every par's worth of extra queries, down to 30. |