Dataset Viewer
Auto-converted to Parquet Duplicate
question
stringlengths
18
249
sql
stringlengths
31
552
level
stringclasses
3 values
how much revenue was there in Q3 2026
SELECT SUM(oi.quantity * oi.unit_price) AS revenue FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.status != 'cancelled' AND o.order_date BETWEEN '2026-07-01' AND '2026-09-30'
easy
average order value without discount codes
SELECT AVG(order_total) AS avg_order_value FROM (SELECT o.order_id, SUM(oi.quantity * oi.unit_price) AS order_total FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.status <> 'cancelled' AND o.discount_code IS NULL GROUP BY o.order_id)
medium
Which product has the highest refund total?
SELECT p.name, SUM(r.refund_amount) AS total_refund FROM returns r JOIN products p ON r.product_id = p.product_id GROUP BY p.product_id ORDER BY total_refund DESC LIMIT 1
easy
How many orders have been shipped but not yet delivered?
SELECT COUNT(*) FROM orders WHERE status = 'shipped'
hard
How many delivered orders had a return for a product that was launched after the order date?
SELECT COUNT(DISTINCT o.order_id) FROM orders o JOIN returns r ON o.order_id = r.order_id JOIN order_items oi ON o.order_id = oi.order_id JOIN products p ON oi.product_id = p.product_id WHERE o.status = 'delivered' AND p.launched_on > o.order_date
hard
How many customers are from either the USA or Canada?
SELECT COUNT(*) FROM customers WHERE country IN ('USA', 'Canada')
hard
How many consumers have a higher average rating than the overall average rating for products they reviewed?
SELECT COUNT(*) AS consumer_count FROM (SELECT r.customer_id FROM reviews r JOIN products p ON r.product_id = p.product_id GROUP BY r.customer_id HAVING AVG(r.rating) > (SELECT AVG(rating) FROM reviews)) AS filtered
medium
What's the top revenue product right now?
SELECT p.product_id, p.name, SUM(oi.quantity * oi.unit_price) AS revenue FROM order_items oi JOIN orders o ON oi.order_id = o.order_id JOIN products p ON oi.product_id = p.product_id WHERE o.status <> 'cancelled' GROUP BY p.product_id, p.name ORDER BY revenue DESC LIMIT 1
medium
How many customers are located in each country represented in the customers table?
SELECT country, COUNT(*) AS customer_count FROM customers GROUP BY country
medium
What's the average order value for store channel orders in September 2026?
SELECT AVG(revenue) AS avg_order_value FROM (SELECT o.order_id, SUM(oi.quantity * oi.unit_price) AS revenue FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.channel = 'store' AND o.status != 'cancelled' AND o.order_date >= '2026-09-01' AND o.order_date < '2026-10-01' GROUP BY o.order_id) t
medium
monthly revenue for last month
SELECT SUM(order_items.quantity * order_items.unit_price) AS monthly_revenue FROM orders JOIN order_items ON orders.order_id = order_items.order_id WHERE orders.status <> 'cancelled' AND orders.order_date >= '2026-09-01' AND orders.order_date <= '2026-09-30'
easy
How many reviews did products in the 'electronics' category get this year?
SELECT COUNT(*) FROM reviews r JOIN products p ON r.product_id = p.product_id JOIN categories c ON p.category_id = c.category_id WHERE c.name = 'electronics' AND r.review_date >= '2026-01-01' AND r.review_date <= '2026-12-31'
hard
How many customers signed up in this year?
SELECT COUNT(*) AS customer_count FROM customers WHERE signup_date >= '2026-01-01' AND signup_date <= '2026-12-31'
medium
What are the average ratings grouped by product?
SELECT product_id, AVG(rating) AS average_rating FROM reviews GROUP BY product_id
easy
How many returns were made for products in the 'electronics' category during this year?
SELECT COUNT(*) FROM returns r JOIN products p ON r.product_id = p.product_id JOIN categories cat ON p.category_id = cat.category_id WHERE cat.name = 'electronics' AND r.return_date >= '2026-01-01' AND r.return_date <= '2026-10-01'
medium
Which product had the most returns this year?
SELECT p.name, COUNT(rt.return_id) AS return_count FROM returns rt JOIN products p ON rt.product_id = p.product_id WHERE rt.return_date >= '2026-01-01' AND rt.return_date < '2027-01-01' GROUP BY p.product_id ORDER BY return_count DESC LIMIT 1
easy
number of cancelled orders with discount codes in October 2026
SELECT COUNT(*) AS cancelled_count FROM orders WHERE order_date >= '2026-10-01' AND order_date < '2026-11-01' AND status = 'cancelled' AND discount_code IS NOT NULL
medium
How many customers are in Germany?
SELECT COUNT(*) FROM customers WHERE country = 'Germany'
medium
What's the average rating for each product, and how many reviews did it get?
SELECT p.product_id, p.name, AVG(r.rating) AS avg_rating, COUNT(r.review_id) AS review_count FROM reviews r JOIN products p ON r.product_id = p.product_id GROUP BY p.product_id, p.name ORDER BY p.product_id
medium
How many reviews did customers in the USA give in this year?
SELECT COUNT(*) AS review_count FROM reviews r JOIN customers c ON r.customer_id = c.customer_id WHERE c.country = 'USA' AND r.review_date >= '2026-01-01' AND r.review_date < '2027-01-01'
medium
What was the average order value for orders placed in the last 7 days?
SELECT AVG(total) FROM (SELECT o.order_id, SUM(oi.quantity * oi.unit_price) AS total FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.order_date >= date('2026-10-01', '-7 days') AND o.order_date < '2026-10-01' AND o.status != 'cancelled' GROUP BY o.order_id) AS order_totals
medium
How many new customers signed up in Canada this year?
SELECT COUNT(*) FROM customers WHERE signup_date >= '2026-01-01' AND signup_date < '2027-01-01' AND country = 'Canada'
easy
Count of business segment customers who signed up in Q3 2026
SELECT COUNT(*) FROM customers WHERE segment = 'business' AND signup_date >= '2026-07-01' AND signup_date <= '2026-09-30'
easy
What is the average revenue per order for orders placed in the last quarter (2026-07-01 to 2026-09-30)?
SELECT AVG(order_value) AS average_order_value FROM (SELECT o.order_id, SUM(oi.quantity * oi.unit_price) AS order_value FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.order_date >= '2026-07-01' AND o.order_date <= '2026-09-30' AND o.status <> 'cancelled' GROUP BY o.order_id)
easy
total revenue from delivered orders
SELECT SUM(oi.quantity * oi.unit_price) AS total_revenue FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.status = 'delivered'
easy
What was the total revenue generated by business customers in the last quarter of 2026?
SELECT SUM(oi.quantity * oi.unit_price) AS revenue FROM order_items oi JOIN orders o ON oi.order_id = o.order_id JOIN customers c ON o.customer_id = c.customer_id WHERE o.order_date >= '2026-07-01' AND o.order_date <= '2026-09-30' AND c.segment = 'business' AND o.status != 'cancelled'
medium
total revenue from app channel orders this year
SELECT SUM(oi.quantity * oi.unit_price) AS revenue FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.status != 'cancelled' AND o.channel = 'app' AND o.order_date >= '2026-01-01' AND o.order_date < '2027-01-01'
easy
number of delivered orders for customers in the USA
SELECT COUNT(*) AS delivered_order_count FROM orders o JOIN customers c ON o.customer_id = c.customer_id WHERE c.country = 'USA' AND o.status = 'delivered'
medium
How many orders were placed in the last 30 days (from 2026-10-01) that have a status of 'placed'?
SELECT COUNT(*) AS order_count FROM orders WHERE order_date >= date('2026-10-01', '-30 days') AND order_date <= '2026-10-01' AND status = 'placed'
medium
What's the average rating for the top products? Like the top 3 by rating.
SELECT p.name AS product_name, AVG(r.rating) AS avg_rating FROM reviews r JOIN products p ON r.product_id = p.product_id GROUP BY p.product_id, p.name ORDER BY avg_rating DESC LIMIT 3
medium
What is the average number of items per order for orders placed in the last 30 days (from 2026-10-01)?
SELECT SUM(oi.quantity) * 1.0 / COUNT(DISTINCT o.order_id) AS avg_items_per_order FROM orders o LEFT JOIN order_items oi ON o.order_id = oi.order_id WHERE o.order_date >= date('2026-10-01', '-30 days')
medium
What is the total refund amount for returns due to wrong item?
SELECT SUM(refund_amount) AS wrong_item_refund FROM returns WHERE reason = 'wrong item'
easy
What is the maximum refund amount given for a return of a product in the category with the highest total cost?
WITH category_cost AS (SELECT p.category_id, SUM(p.cost) AS total_cost FROM products p GROUP BY p.category_id), top_cat AS (SELECT category_id FROM category_cost ORDER BY total_cost DESC LIMIT 1) SELECT MAX(r.refund_amount) AS max_refund FROM returns r JOIN products p ON r.product_id = p.product_id WHERE p.category_id ...
hard
How many repeat buyers do we have?
SELECT COUNT(*) AS repeat_buyer_count FROM (SELECT customer_id FROM orders GROUP BY customer_id HAVING COUNT(DISTINCT order_id) > 1)
medium
How many 5-star reviews did product 1 get?
SELECT COUNT(*) AS five_star_count FROM reviews WHERE product_id = 1 AND rating = 5
medium
How many reviews did each product receive?
SELECT product_id, COUNT(*) AS review_count FROM reviews GROUP BY product_id
easy
orders in the last 30 days
SELECT * FROM orders WHERE order_date >= date('2026-10-01', '-30 days')
easy
What was the total revenue from orders that used a discount code last month?
SELECT SUM(oi.quantity * oi.unit_price) FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.order_date >= '2026-09-01' AND o.order_date <= '2026-09-30' AND o.status != 'cancelled' AND o.discount_code IS NOT NULL
easy
What is the total revenue generated by orders that used a discount code in the last month (September 2026)?
SELECT SUM(oi.quantity * oi.unit_price) AS total_revenue FROM order_items oi JOIN orders o ON oi.order_id = o.order_id WHERE o.order_date >= '2026-09-01' AND o.order_date < '2026-10-01' AND o.status != 'cancelled' AND o.discount_code IS NOT NULL
hard
customers who never ordered
SELECT c.customer_id, c.name, c.email FROM customers c WHERE NOT EXISTS (SELECT 1 FROM orders o WHERE o.customer_id = c.customer_id)
easy
How many customers are from Australia?
SELECT COUNT(*) FROM customers WHERE country = 'Australia'
medium
monthly revenue for month last month
SELECT COALESCE(SUM(oi.quantity * oi.unit_price), 0) AS monthly_revenue FROM orders AS o JOIN order_items AS oi ON o.order_id = oi.order_id WHERE o.status <> 'cancelled' AND o.order_date BETWEEN '2026-09-01' AND '2026-09-30'
medium
What is the average rating of products that have been returned?
SELECT AVG(r.rating) AS avg_rating FROM reviews r WHERE r.product_id IN (SELECT DISTINCT product_id FROM returns)
hard
How many new customers signed up in the last 7 days?
SELECT COUNT(*) AS new_customers FROM customers WHERE signup_date >= date('2026-10-01', '-7 days')
easy
What are the customer counts by segment for customers in each country?
SELECT country, segment, COUNT(*) AS customer_count FROM customers GROUP BY country, segment ORDER BY country, segment
medium
How many customers are from Canada?
SELECT COUNT(*) FROM customers WHERE country = 'Canada'
hard
What is the average quantity of items ordered per order for delivered orders in September 2026?
SELECT AVG(total_qty) AS avg_items_per_order FROM (SELECT o.order_id, SUM(oi.quantity) AS total_qty FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.status = 'delivered' AND o.order_date >= '2026-09-01' AND o.order_date < '2026-10-01' GROUP BY o.order_id) AS order_qty
easy
count of products with price > 200 in category 'Audio'?
SELECT COUNT(*) FROM products p JOIN categories c ON p.category_id = c.category_id WHERE c.name = 'Audio' AND p.price > 200
easy
Which product has the highest refund amount from returns?
SELECT r.product_id, SUM(r.refund_amount) AS total_refund FROM returns r GROUP BY r.product_id ORDER BY total_refUND DESC LIMIT 1
hard
total revenue by month for 2026
SELECT strftime('%Y-%m', o.order_date) AS month, SUM(oi.quantity * oi.unit_price) AS revenue FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.status != 'cancelled' AND o.order_date BETWEEN '2026-01-01' AND '2026-12-31' GROUP BY month ORDER BY month
easy
What is the refund amount for the return with return_id 1?
SELECT refund_amount FROM returns WHERE return_id = 1
easy
How many customers are in the business segment from the UK?
SELECT COUNT(*) FROM customers WHERE segment = 'business' AND country = 'UK'
medium
how many delivered orders were placed in last quarter
SELECT COUNT(*) FROM orders WHERE status = 'delivered' AND order_date >= '2026-07-01' AND order_date <= '2026-09-30'
hard
How many returns have been made for product 4 in the last 30 days?
SELECT COUNT(*) FROM returns WHERE product_id = 4 AND return_date >= date('2026-10-01', '-30 days')
easy
What is the total revenue from orders that were not cancelled?
SELECT SUM(oi.quantity * oi.unit_price) AS revenue FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.status <> 'cancelled'
hard
How many customers from the USA placed orders that were never delivered?
SELECT COUNT(DISTINCT c.customer_id) FROM customers c JOIN orders o ON c.customer_id = o.customer_id WHERE c.country = 'USA' AND o.status != 'delivered'
hard
What was the average order value for cancelled orders placed in September 2026?
SELECT AVG(order_value) AS average_order_value FROM (SELECT o.order_id, SUM(oi.quantity * oi.unit_price) AS order_value FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.order_date >= '2026-09-01' AND o.order_date <= '2026-09-30' AND o.status = 'cancelled' GROUP BY o.order_id)
easy
How many distinct customers placed orders in the last 7 days (2026-10-01 to 2026-10-01)?
SELECT COUNT(DISTINCT customer_id) AS distinct_customers FROM orders WHERE order_date >= date('2026-10-01', '-7 days')
hard
How many reviews does product 1 have?
SELECT COUNT(*) FROM reviews WHERE product_id = 1
easy
Which customer has the highest total spend this year?
SELECT c.customer_id, c.name, SUM(oi.quantity * oi.unit_price) AS total_spend FROM customers c JOIN orders o ON c.customer_id = o.customer_id JOIN order_items oi ON o.order_id = oi.order_id WHERE o.status != 'cancelled' AND o.order_date BETWEEN '2026-01-01' AND '2026-12-31' GROUP BY c.customer_id, c.name ORDER BY total...
medium
What is the worst rated product by average rating?
SELECT product_id, AVG(rating) AS avg_rating FROM reviews GROUP BY product_id ORDER BY avg_rating ASC LIMIT 1
hard
What's the total number of customers in the consumer segment?
SELECT COUNT(*) FROM customers WHERE segment = 'consumer'
medium
How many customers are located in the city of Paris?
SELECT COUNT(*) FROM customers WHERE city = 'Paris'
easy
What is the refund amount for returns due to not as described?
SELECT SUM(refund_amount) AS refund_amount FROM returns WHERE reason = 'not as described'
easy
How many reviews were written for each product, and what is the average rating?
SELECT p.product_id, p.name, COUNT(r.review_id) AS review_count, AVG(r.rating) AS average_rating FROM products p JOIN reviews r ON p.product_id = r.product_id GROUP BY p.product_id, p.name ORDER BY p.product_id
easy
What is the total revenue generated in 2026 so far this year?
SELECT SUM(o.quantity * o.unit_price) AS revenue FROM order_items o JOIN orders r ON o.order_id = r.order_id WHERE r.order_date BETWEEN '2026-01-01' AND '2026-10-01' AND r.status != 'cancelled'
medium
What is the average rating of reviews for products launched in 2026?
SELECT AVG(r.rating) FROM reviews r JOIN products p ON r.product_id = p.product_id WHERE p.launched_on >= '2026-01-01' AND p.launched_on <= '2026-12-31'
easy
What's the average rating for products reviewed this year?
SELECT AVG(r.rating) AS avg_rating FROM reviews r WHERE r.review_date >= '2026-01-01'
medium
How many customers signed up in last month?
SELECT COUNT(*) FROM customers WHERE signup_date >= '2026-09-01' AND signup_date < '2026-10-01'
medium
How many customers are in cities of Japan?
SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Japan'
medium
How many products were launched in the last quarter of 2026 across all parent categories?
SELECT COUNT(*) FROM products WHERE launched_on >= '2026-07-01' AND launched_on < '2026-10-01'
medium
How many delivered orders had the web channel last month?
SELECT COUNT(*) FROM orders WHERE channel = 'web' AND status = 'delivered' AND order_date >= '2026-09-01' AND order_date <= '2026-09-30'
easy
How many customers signed up in 2025 from the USA
SELECT COUNT(*) FROM customers WHERE signup_date LIKE '2025-%' AND country = 'USA'
hard
What is the average order value for orders placed by business customers in September 2026?
SELECT AVG(order_value) FROM (SELECT o.order_id, SUM(oi.quantity * oi.unit_price) AS order_value FROM orders o JOIN customers c ON o.customer_id = c.customer_id JOIN order_items oi ON o.order_id = oi.order_id WHERE c.segment = 'business' AND o.status <> 'cancelled' AND o.order_date BETWEEN '2026-09-01' AND '2026-09-30'...
medium
how much revenue was generated in the last 7 days
SELECT SUM(oi.quantity * oi.unit_price) AS revenue FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.status != 'cancelled' AND o.order_date >= date('2026-10-01', '-7 days') AND o.order_date <= '2026-10-01'
easy
Which product has the best average rating?
SELECT product_id, AVG(rating) AS avg_rating FROM reviews GROUP BY product_id ORDER BY avg_rating DESC LIMIT 1
easy
How many products have been reviewed at least once?
SELECT COUNT(DISTINCT product_id) AS product_count FROM reviews
medium
How did the revenue from the store channel compare to the web channel for September 2026?
SELECT SUM(CASE WHEN o.channel = 'store' THEN oi.quantity * oi.unit_price ELSE 0 END) AS store_revenue, SUM(CASE WHEN o.channel = 'web' THEN oi.quantity * oi.unit_price ELSE 0 END) AS web_revenue FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.status != 'cancelled' AND o.order_date BETWEEN '2026-0...
medium
How many customers are located in France and what is the total number of customers in the consumer segment there?
SELECT COUNT(customer_id) AS france_consumers FROM customers WHERE country = 'France' AND segment = 'consumer'
medium
What is the total number of new customers who signed up in October 2026?
SELECT COUNT(*) AS total_new_customers FROM customers WHERE signup_date >= '2026-10-01' AND signup_date < '2026-11-01'
medium
What are the counts of customers by country for the top 3 countries?
SELECT country, COUNT(*) AS customer_count FROM customers GROUP BY country ORDER BY customer_count DESC LIMIT 3
easy
Which customer spent the most money in total?
SELECT c.customer_id, c.name, SUM(oi.quantity * oi.unit_price) AS total_spent FROM orders o JOIN order_items oi ON o.order_id = oi.order_id JOIN customers c ON o.customer_id = c.customer_id WHERE o.status <> 'cancelled' GROUP BY c.customer_id, c.name ORDER BY total_spent DESC LIMIT 1
hard
How many customers from Canada placed their first-ever order in September 2026?
SELECT COUNT(*) AS customer_count FROM customers AS c WHERE c.country = 'Canada' AND c.customer_id IN ( SELECT customer_id FROM orders GROUP BY customer_id HAVING MIN(order_date) BETWEEN '2026-09-01' AND '2026-09-30' )
medium
Which sales channel had the highest revenue in September 2026?
SELECT o.channel, SUM(oi.quantity * oi.unit_price) AS revenue FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.status != 'cancelled' AND o.order_date BETWEEN '2026-09-01' AND '2026-09-30' GROUP BY o.channel ORDER BY revenue DESC LIMIT 1
medium
What is the average rating given by customers to each product they have reviewed?
SELECT product_id, AVG(rating) AS average_rating FROM reviews GROUP BY product_id
easy
How many shipped orders had a discount code in the last quarter?
SELECT COUNT(*) FROM orders WHERE discount_code IS NOT NULL AND status = 'shipped' AND order_date >= '2026-07-01' AND order_date <= '2026-09-30'
medium
top 3 customers by total spent in 2026?
SELECT c.customer_id, c.name, SUM(oi.quantity * oi.unit_price) AS total_spent FROM orders o JOIN order_items oi ON o.order_id = oi.order_id JOIN customers c ON o.customer_id = c.customer_id WHERE o.status != 'cancelled' AND o.order_date >= '2026-01-01' AND o.order_date < '2027-01-01' GROUP BY c.customer_id, c.name ORDE...
easy
What is the customer count by segment?
SELECT segment, COUNT(customer_id) AS customer_count FROM customers GROUP BY segment
medium
Show me the top 3 products by total revenue this year, excluding cancelled orders.
SELECT p.name, SUM(oi.quantity * oi.unit_price) AS total_revenue FROM order_items oi JOIN orders o ON oi.order_id = o.order_id JOIN products p ON oi.product_id = p.product_id WHERE o.status != 'cancelled' AND strftime('%Y', o.order_date) = '2026' GROUP BY p.product_id ORDER BY total_revenue DESC LIMIT 3
hard
What is the total refund amount for all returns?
SELECT SUM(refund_amount) AS total_refund_amount FROM returns
easy
What is the refund amount for returns of products that were not returned within 30 days of delivery in September 2026?
SELECT COALESCE(SUM(r.refund_amount), 0) AS refund_amount FROM returns r JOIN orders o ON r.order_id = o.order_id WHERE r.return_date >= '2026-09-01' AND r.return_date < '2026-10-01' AND r.return_date > date(o.order_date, '+30 days')
hard
average refund amount by return reason
SELECT reason, AVG(refund_amount) FROM returns GROUP BY reason
easy
How many orders had to be cancelled last month?
SELECT COUNT(*) AS cancelled_orders FROM orders WHERE status = 'cancelled' AND order_date BETWEEN '2026-09-01' AND '2026-09-30'
easy
Which product has the worst average rating?
SELECT product_id, AVG(rating) AS avg_rating FROM reviews GROUP BY product_id ORDER BY avg_rating ASC LIMIT 1
easy
What's the total revenue by week for delivered orders in September 2026?
SELECT strftime('%Y-%W', o.order_date) AS week, SUM(oi.quantity * oi.unit_price) AS revenue FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.status = 'delivered' AND o.order_date >= '2026-09-01' AND o.order_date < '2026-10-01' GROUP BY week ORDER BY week
medium
Which customers spent the most money in September 2026?
SELECT c.customer_id, c.name, c.email, SUM(oi.quantity * oi.unit_price) AS total_spent FROM orders o JOIN order_items oi ON o.order_id = oi.order_id JOIN customers c ON o.customer_id = c.customer_id WHERE o.status <> 'cancelled' AND o.order_date >= '2026-09-01' AND o.order_date <= '2026-09-30' GROUP BY c.customer_id, c...
hard
What is the total profit for all delivered orders in September 2026, calculated as SUM(quantity * unit_price) minus SUM(quantity * cost) per order item?
SELECT SUM(oi.quantity * oi.unit_price - oi.quantity * p.cost) AS total_profit FROM orders o JOIN order_items oi ON o.order_id = oi.order_id JOIN products p ON oi.product_id = p.product_id WHERE o.status = 'delivered' AND o.order_date >= '2026-09-01' AND o.order_date <= '2026-09-30'
hard
What's the total revenue from orders with no discount code this year?
SELECT SUM(oi.quantity * oi.unit_price) AS revenue FROM order_items oi JOIN orders o ON oi.order_id = o.order_id WHERE o.discount_code IS NULL AND o.status IN ('placed', 'shipped', 'delivered') AND o.order_date >= '2026-01-01' AND o.order_date <= '2026-12-31'
medium
What's the total quantity of products sold in the last 30 days from the start of October 2026?
SELECT SUM(oi.quantity) AS total_quantity FROM orders o JOIN order_items oi ON o.order_id = oi.order_id WHERE o.order_date >= date('2026-10-01', '-30 days') AND o.order_date <= '2026-10-01' AND o.status <> 'cancelled'
medium
How many orders were placed in the last 30 days?
SELECT COUNT(*) FROM orders WHERE order_date >= date('2026-10-01', '-30 days')
hard
End of preview. Expand in Data Studio

Shop SQL: text-to-SQL pairs distilled from Flint

This dataset has 1,244 English questions paired with SQLite queries for one demo database, an online shop. Every pair was written and checked by Recursive Flint (40B-A2.5B) running locally on a Mac. It was used to train alexwengg/shop-sql-0.6b-mlx-4bit, a 331 MB model that answers in about 0.2 s.

The repo also has everything needed to reproduce or extend it: the database, the data generator, the training config, the evaluation script and an interactive demo.

The database

shop.db is a synthetic SQLite database with about 41.6k rows covering 2024-01-01 to 2026-09-30. "Today" is fixed at 2026-10-01. make_db.py rebuilds it byte for byte.

Table Rows Columns
customers 2,500 customer_id, name, email, city, country, segment, signup_date
categories 24 category_id, name, parent_id (a two-level tree)
products 144 product_id, name, category_id, price, cost, launched_on, is_active
orders 15,166 order_id, customer_id, order_date, status, channel, discount_code
order_items 19,794 order_id, product_id, quantity, unit_price
returns 779 return_id, order_id, product_id, return_date, reason, refund_amount
reviews 3,183 review_id, product_id, customer_id, rating, review_date

The data has realistic patterns: growth over time, a holiday season, Black Friday spikes, a few heavy buyers, discount codes and higher return rates in some categories. All names and emails are made up.

Configs

pairs (default): the verified pairs, one JSON object per line.

{"question": "How many customers are in the country France?",
 "sql": "SELECT COUNT(*) FROM customers WHERE country = 'France'",
 "level": "easy"}
Split Pairs
train 1,058
validation 62
test 124

Across all splits there are 473 easy, 543 medium and 228 hard questions.

candidates: all 2,403 generated candidates, including rejected ones. Fields:

  • question
  • sql_a: Flint's proposed query
  • sql_b: Flint's independent answer
  • topic, level, style
  • err_a, err_b: SQLite errors, if any
  • kept: the verdict at generation time

build_dataset.py re-scores every candidate with the final comparison rule, which also accepts an answer with extra descriptive columns, such as a product name next to its ID. That re-scoring is how the 1,244 pairs were selected.

How it was made

  1. Propose: Flint wrote question/SQL pairs for one of 20 topics (revenue over time, category rollups, returns, cohorts, window functions, anti-joins and more), at one of three difficulty levels (35/45/20%) and in one of three question styles. A pre-filled JSON reply forced it to write the pairs directly.
  2. Answer independently: Flint answered each question again from scratch, with reasoning on (up to 3,000 tokens), using the system prompt the student model uses.
  3. Verify: a pair was kept only if both queries ran on shop.db and returned the same non-empty result. Rows are compared regardless of order, and floats are rounded to 2 decimals. 1,244 of 2,403 candidates (52%) passed.
  4. Split: the pairs were shuffled with seed 0 into 85/5/10 train/validation/test. The target SQL is the shorter of the two agreeing queries, collapsed onto one line.

Both prompts share fixed date conventions: "last month" is September 2026, "this year" is 2026, "last quarter" is Q3 2026, and "last N days" means order_date >= date('2026-10-01', '-N days'). With these, each question has one correct answer.

Results on the test split

Model Execution accuracy Latency p50
Qwen3-0.6B, no fine-tuning 21.8% 0.36 s
shop-sql-0.6b-mlx-4bit 82.3% 0.21 s
Flint, 3-bit MLX, with reasoning 97.6% 7.4 s

Per-question predictions are in results/. Flint's score is an upper bound, because the reference answers come from Flint itself.

Files

Path What it is
shop.db, make_db.py The database and its deterministic generator
common.py System prompt, read-only SQL execution, result comparison
gen_data.py Teacher data generation (needs Flint as an MLX model; see below)
build_dataset.py Re-scores candidates and writes the splits
data/sft/ Chat-format train/valid files, as used by mlx_lm.lora
lora.yaml The LoRA training config (Qwen3-0.6B, rank 32, 800 steps)
evaluate.py Execution accuracy and latency for the student or the teacher
demo/ Web demo: ask in English and watch the tables filter down into the result
results/ Test-set predictions for the base model, the student and Flint

Run it

On a Mac with Apple Silicon:

pip install -r requirements.txt
hf download alexwengg/shop-sql-flint-distill --repo-type dataset --local-dir shop-sql && cd shop-sql
python demo/server.py              # loads alexwengg/shop-sql-0.6b-mlx-4bit, open http://localhost:8017
python evaluate.py student --model alexwengg/shop-sql-0.6b-mlx-4bit
python -m mlx_lm lora -c lora.yaml # retrain the adapter

To generate more data you need Flint as an MLX model. On 2026-10-22, MLX support for Flint was in an open pull request (ml-explore/mlx-lm#1998). The data here came from a mixed 3/6-bit conversion that fits a 24 GB Mac: routed experts at 3 bits, everything else at 6. Point gen_data.py --teacher at your conversion.

Limitations

  • One synthetic schema. This is a narrow distillation dataset, not a general text-to-SQL benchmark.
  • The reference answers are model-made. Two independent Flint runs agreeing is a strong filter, but nobody checked the answers by hand. Some pairs will be wrong in the same way twice.
  • Hard questions are under-represented (18%), and they're where the student is weakest.
  • SQLite dialect (strftime, date('2026-10-01', '-1 month')).

License

Apache 2.0. Flint's outputs are used under its Apache 2.0 license.

Downloads last month
90

Models trained or fine-tuned on alexwengg/shop-sql-flint-distill