SaluteFaceOpensource's picture SalutefaceAAC's picture
Duplicate from SalutefaceAAC/sql-natural-language-pairs
606ac8d
Raw History Blame Contribute Delete
163 kB
question,sql,schema_context,domain,difficulty,query_type
List all customers from Germany.,SELECT * FROM customers WHERE country = 'Germany';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Show the names and emails of all customers.,"SELECT name, email FROM customers;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Find all orders with status 'pending'.,SELECT * FROM orders WHERE status = 'pending';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Get the top 10 most expensive products.,SELECT * FROM products ORDER BY price DESC LIMIT 10;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
List products with stock quantity below 20.,"SELECT name, stock_quantity FROM products WHERE stock_quantity < 20;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Show all orders placed in 2024.,SELECT * FROM orders WHERE order_date >= '2024-01-01' AND order_date < '2025-01-01';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Find customers who spent more than 1000 in total.,SELECT * FROM customers WHERE total_spent > 1000;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
List all product categories.,SELECT DISTINCT category FROM products;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Get all suppliers from the United States.,SELECT * FROM suppliers WHERE country = 'United States';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Find all cancelled orders.,SELECT * FROM orders WHERE status = 'cancelled';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
List all patients from New York.,SELECT * FROM patients WHERE city = 'New York';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
Show all doctors with specialty 'Cardiology'.,SELECT * FROM doctors WHERE specialty = 'Cardiology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
Find all appointments scheduled for today.,SELECT * FROM appointments WHERE appointment_date = CURRENT_DATE;," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
List hospitals with a rating above 4.,SELECT * FROM hospitals WHERE rating > 4;," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
Get all female patients.,SELECT * FROM patients WHERE gender = 'F';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
Find all confirmed appointments.,SELECT * FROM appointments WHERE status = 'confirmed';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
List prescriptions with duration longer than 30 days.,SELECT * FROM prescriptions WHERE duration_days > 30;," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
Show all doctors with more than 10 years of experience.,SELECT * FROM doctors WHERE years_experience > 10;," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
Find all active users.,SELECT * FROM users WHERE is_active = TRUE;," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,select
List all users on the 'pro' plan.,SELECT * FROM users WHERE plan = 'pro';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,select
Show all page view events.,SELECT * FROM events WHERE event_type = 'page_view';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,select
"Find users who signed up after January 1, 2023.",SELECT * FROM users WHERE signup_date > '2023-01-01';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,select
Get sessions that lasted more than 10 minutes.,SELECT * FROM events WHERE duration_seconds > 600;," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,select
List all employees in the Engineering department.,SELECT e.* FROM employees e JOIN departments d ON e.department_id = d.department_id WHERE d.name = 'Engineering';," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,select
Find employees with salary above 80000.,SELECT * FROM employees WHERE salary > 80000;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,select
List all employees hired in 2022.,SELECT * FROM employees WHERE hire_date >= '2022-01-01' AND hire_date < '2023-01-01';," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,select
Show all projects with a budget over 500000.,SELECT * FROM projects WHERE budget > 500000;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,select
Find employees who received a performance rating of 5.,SELECT e.name FROM employees e JOIN performance_reviews pr ON e.employee_id = pr.employee_id WHERE pr.rating = 5;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,select
List all items with quantity below the reorder point.,"SELECT i.name, i.reorder_point, s.quantity FROM items i JOIN stock s ON i.item_id = s.item_id WHERE s.quantity < i.reorder_point;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
Find all warehouses in the United States.,SELECT * FROM warehouses WHERE country = 'United States';," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
Show all stock movements of type 'receipt' from last month.,"SELECT * FROM movements WHERE movement_type = 'receipt' AND movement_date >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month');"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
How many customers are there in total?,SELECT COUNT(*) AS total_customers FROM customers;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from all orders?,SELECT SUM(total_amount) AS total_revenue FROM orders;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average product price?,SELECT AVG(price) AS avg_price FROM products;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the most expensive product price?,SELECT MAX(price) AS max_price FROM products;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many orders are in 'shipped' status?,SELECT COUNT(*) AS shipped_count FROM orders WHERE status = 'shipped';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average salary of all employees?,SELECT AVG(salary) AS avg_salary FROM employees;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,aggregate
How many hospitals have more than 200 beds?,SELECT COUNT(*) FROM hospitals WHERE beds > 200;," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
What is the total quantity of all items in stock?,SELECT SUM(quantity) AS total_stock FROM stock;," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
How many distinct event types are there?,SELECT COUNT(DISTINCT event_type) AS event_type_count FROM events;," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the minimum salary in the company?,SELECT MIN(salary) AS min_salary FROM employees;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,aggregate
List all orders along with the customer name and email.,"SELECT o.order_id, c.name, c.email, o.order_date, o.total_amount
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
Show each order item with product name and unit price.,"SELECT oi.item_id, p.name AS product_name, oi.quantity, oi.unit_price
FROM order_items oi
JOIN products p ON oi.product_id = p.product_id;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
Find all orders placed by customers from France.,"SELECT o.*
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id
WHERE c.country = 'France';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
List each product with its supplier name and supplier country.,"SELECT p.name AS product_name, s.name AS supplier_name, s.country
FROM products p
JOIN suppliers s ON p.supplier_id = s.supplier_id;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
"Show all appointments with patient name, doctor name, and diagnosis.","SELECT a.appointment_id, p.name AS patient_name, d.name AS doctor_name,
a.appointment_date, a.diagnosis
FROM appointments a
JOIN patients p ON a.patient_id = p.patient_id
JOIN doctors d ON a.doctor_id = d.doctor_id;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
List each doctor along with the hospital name and city they work in.,"SELECT d.name AS doctor_name, d.specialty, h.name AS hospital_name, h.city
FROM doctors d
JOIN hospitals h ON d.hospital_id = h.hospital_id;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
Find all prescriptions for patients diagnosed with 'Hypertension'.,"SELECT pr.*, p.name AS patient_name
FROM prescriptions pr
JOIN appointments a ON pr.appointment_id = a.appointment_id
JOIN patients p ON a.patient_id = p.patient_id
WHERE a.diagnosis = 'Hypertension';"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
List each employee with their department name and location.,"SELECT e.name, e.salary, d.name AS department_name, d.location
FROM employees e
JOIN departments d ON e.department_id = d.department_id;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,join
"Show all employees assigned to a project, with the project name and their role.","SELECT e.name AS employee_name, p.name AS project_name, a.role, a.hours_per_week
FROM assignments a
JOIN employees e ON a.employee_id = e.employee_id
JOIN projects p ON a.project_id = p.project_id;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,join
"Find all user sessions that lasted more than 30 minutes, with the username.","SELECT u.username, s.session_id, s.start_time, s.end_time, s.device
FROM sessions s
JOIN users u ON s.user_id = u.user_id
WHERE EXTRACT(EPOCH FROM (s.end_time - s.start_time)) > 1800;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,join
List all events with the username and the session device.,"SELECT e.event_id, u.username, e.event_type, e.event_date, s.device
FROM events e
JOIN users u ON e.user_id = u.user_id
JOIN sessions s ON e.session_id = s.session_id;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,join
List each item in stock with its warehouse name and city.,"SELECT i.name AS item_name, i.sku, w.name AS warehouse_name, w.city, s.quantity
FROM stock s
JOIN items i ON s.item_id = i.item_id
JOIN warehouses w ON s.warehouse_id = w.warehouse_id;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,join
Find all receipt movements with the item name and warehouse name.,"SELECT m.movement_id, i.name AS item_name, w.name AS warehouse_name,
m.quantity, m.movement_date
FROM movements m
JOIN items i ON m.item_id = i.item_id
JOIN warehouses w ON m.warehouse_id = w.warehouse_id
WHERE m.movement_type = 'receipt';"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,join
How many orders does each customer have?,"SELECT customer_id, COUNT(*) AS order_count
FROM orders
GROUP BY customer_id
ORDER BY order_count DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
What is the total revenue per product category?,"SELECT p.category, SUM(oi.quantity * oi.unit_price) AS category_revenue
FROM order_items oi
JOIN products p ON oi.product_id = p.product_id
GROUP BY p.category
ORDER BY category_revenue DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
How many products are in each category?,"SELECT category, COUNT(*) AS product_count
FROM products
GROUP BY category
ORDER BY product_count DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
What is the average order value per customer country?,"SELECT c.country, AVG(o.total_amount) AS avg_order_value
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id
GROUP BY c.country
ORDER BY avg_order_value DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
How many appointments does each doctor have?,"SELECT doctor_id, COUNT(*) AS appointment_count
FROM appointments
GROUP BY doctor_id
ORDER BY appointment_count DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,aggregate
What is the average number of beds per city?,"SELECT city, AVG(beds) AS avg_beds
FROM hospitals
GROUP BY city
ORDER BY avg_beds DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,aggregate
"How many patients does each hospital serve, by doctor specialty?","SELECT h.name AS hospital_name, d.specialty, COUNT(DISTINCT a.patient_id) AS patient_count
FROM appointments a
JOIN doctors d ON a.doctor_id = d.doctor_id
JOIN hospitals h ON d.hospital_id = h.hospital_id
GROUP BY h.name, d.specialty
ORDER BY patient_count DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,aggregate
What is the average salary by department?,"SELECT d.name AS department_name, AVG(e.salary) AS avg_salary
FROM employees e
JOIN departments d ON e.department_id = d.department_id
GROUP BY d.name
ORDER BY avg_salary DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
How many employees are in each department?,"SELECT d.name AS department, COUNT(e.employee_id) AS employee_count
FROM employees e
JOIN departments d ON e.department_id = d.department_id
GROUP BY d.name
ORDER BY employee_count DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
What is the total number of events per event type?,"SELECT event_type, COUNT(*) AS event_count
FROM events
GROUP BY event_type
ORDER BY event_count DESC;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,aggregate
How many users signed up per month in 2023?,"SELECT DATE_TRUNC('month', signup_date) AS month, COUNT(*) AS signups
FROM users
WHERE signup_date >= '2023-01-01' AND signup_date < '2024-01-01'
GROUP BY month
ORDER BY month;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,aggregate
What is the total stock quantity per warehouse?,"SELECT w.name AS warehouse_name, SUM(s.quantity) AS total_quantity
FROM stock s
JOIN warehouses w ON s.warehouse_id = w.warehouse_id
GROUP BY w.name
ORDER BY total_quantity DESC;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,aggregate
How many shipments were received per item last quarter?,"SELECT i.name AS item_name, SUM(m.quantity) AS received
FROM movements m
JOIN items i ON m.item_id = i.item_id
WHERE m.movement_type = 'receipt'
AND m.movement_date >= DATE_TRUNC('quarter', CURRENT_DATE - INTERVAL '3 months')
AND m.movement_date < DATE_TRUNC('quarter', CURRENT_DATE)
GROUP BY i.name
ORDER BY received DESC;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,aggregate
Find customers who have placed more than 5 orders.,"SELECT customer_id, COUNT(*) AS order_count
FROM orders
GROUP BY customer_id
HAVING COUNT(*) > 5
ORDER BY order_count DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
Which product categories have average price above 100?,"SELECT category, AVG(price) AS avg_price
FROM products
GROUP BY category
HAVING AVG(price) > 100
ORDER BY avg_price DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
Find departments where average employee salary is above 75000.,"SELECT d.name, AVG(e.salary) AS avg_salary
FROM employees e
JOIN departments d ON e.department_id = d.department_id
GROUP BY d.name
HAVING AVG(e.salary) > 75000
ORDER BY avg_salary DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
Which hospitals have more than 100 appointments in total?,"SELECT h.name, COUNT(a.appointment_id) AS total_appointments
FROM appointments a
JOIN doctors d ON a.doctor_id = d.doctor_id
JOIN hospitals h ON d.hospital_id = h.hospital_id
GROUP BY h.name
HAVING COUNT(a.appointment_id) > 100
ORDER BY total_appointments DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,aggregate
Find users who triggered more than 50 events.,"SELECT user_id, COUNT(*) AS event_count
FROM events
GROUP BY user_id
HAVING COUNT(*) > 50
ORDER BY event_count DESC;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,aggregate
Which items have been restocked more than 10 times?,"SELECT i.name, COUNT(m.movement_id) AS restock_count
FROM movements m
JOIN items i ON m.item_id = i.item_id
WHERE m.movement_type = 'receipt'
GROUP BY i.name
HAVING COUNT(m.movement_id) > 10
ORDER BY restock_count DESC;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,aggregate
Find customers who have never placed an order.,"SELECT * FROM customers
WHERE customer_id NOT IN (SELECT DISTINCT customer_id FROM orders);"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
Find the product with the highest total quantity sold.,"SELECT p.name, total_sold
FROM products p
JOIN (
SELECT product_id, SUM(quantity) AS total_sold
FROM order_items
GROUP BY product_id
) s ON p.product_id = s.product_id
ORDER BY total_sold DESC
LIMIT 1;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
List customers whose total spending is above the average total spending.,"SELECT name, total_spent
FROM customers
WHERE total_spent > (SELECT AVG(total_spent) FROM customers)
ORDER BY total_spent DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
Find products that have never been ordered.,"SELECT * FROM products
WHERE product_id NOT IN (SELECT DISTINCT product_id FROM order_items);"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
Find the top 3 customers by total order value in 2024.,"SELECT c.name, SUM(o.total_amount) AS total_value
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id
WHERE o.order_date >= '2024-01-01' AND o.order_date < '2025-01-01'
GROUP BY c.name
ORDER BY total_value DESC
LIMIT 3;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
Find patients who have been prescribed more medications than average.,"SELECT p.name, COUNT(pr.prescription_id) AS prescription_count
FROM patients p
JOIN appointments a ON p.patient_id = a.patient_id
JOIN prescriptions pr ON a.appointment_id = pr.appointment_id
GROUP BY p.patient_id, p.name
HAVING COUNT(pr.prescription_id) > (
SELECT AVG(pcount) FROM (
SELECT COUNT(pr2.prescription_id) AS pcount
FROM appointments a2
JOIN prescriptions pr2 ON a2.appointment_id = pr2.appointment_id
GROUP BY a2.patient_id
) sub
);"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,subquery
Find doctors who have no appointments in the past 6 months.,"SELECT * FROM doctors
WHERE doctor_id NOT IN (
SELECT DISTINCT doctor_id FROM appointments
WHERE appointment_date >= CURRENT_DATE - INTERVAL '6 months'
);"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,subquery
Find employees earning more than the average salary in their own department.,"SELECT e.name, e.salary, d.name AS department
FROM employees e
JOIN departments d ON e.department_id = d.department_id
WHERE e.salary > (
SELECT AVG(e2.salary)
FROM employees e2
WHERE e2.department_id = e.department_id
)
ORDER BY d.name, e.salary DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,subquery
Find the department with the highest total bonus payout.,"SELECT d.name, SUM(pr.bonus) AS total_bonus
FROM performance_reviews pr
JOIN employees e ON pr.employee_id = e.employee_id
JOIN departments d ON e.department_id = d.department_id
GROUP BY d.name
ORDER BY total_bonus DESC
LIMIT 1;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,subquery
Find users who converted but never triggered a 'purchase' event.,"SELECT DISTINCT u.user_id, u.username
FROM conversions c
JOIN users u ON c.user_id = u.user_id
WHERE u.user_id NOT IN (
SELECT user_id FROM events WHERE event_type = 'purchase'
);"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,subquery
Find the page with the highest average session duration.,"SELECT page, AVG(duration_seconds) AS avg_duration
FROM events
GROUP BY page
ORDER BY avg_duration DESC
LIMIT 1;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,subquery
Find items that are stocked in every warehouse.,"SELECT i.name
FROM items i
WHERE NOT EXISTS (
SELECT 1 FROM warehouses w
WHERE NOT EXISTS (
SELECT 1 FROM stock s
WHERE s.item_id = i.item_id AND s.warehouse_id = w.warehouse_id
)
);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,subquery
"Using a CTE, find the monthly revenue trend for 2024.","WITH monthly_revenue AS (
SELECT DATE_TRUNC('month', order_date) AS month,
SUM(total_amount) AS revenue
FROM orders
WHERE order_date >= '2024-01-01' AND order_date < '2025-01-01'
GROUP BY month
)
SELECT month, revenue,
revenue - LAG(revenue) OVER (ORDER BY month) AS month_over_month_change
FROM monthly_revenue
ORDER BY month;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,cte
"Using a CTE, rank customers by total spending and show the top 5.","WITH customer_spending AS (
SELECT c.customer_id, c.name,
SUM(o.total_amount) AS total_spending
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_id, c.name
)
SELECT name, total_spending,
RANK() OVER (ORDER BY total_spending DESC) AS spending_rank
FROM customer_spending
ORDER BY spending_rank
LIMIT 5;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,cte
"Using a CTE, find each department's headcount and its share of total company headcount.","WITH dept_counts AS (
SELECT department_id, COUNT(*) AS headcount
FROM employees
GROUP BY department_id
),
total AS (
SELECT SUM(headcount) AS company_total FROM dept_counts
)
SELECT d.name, dc.headcount,
ROUND(100.0 * dc.headcount / t.company_total, 2) AS pct_of_company
FROM dept_counts dc
JOIN departments d ON dc.department_id = d.department_id
CROSS JOIN total t
ORDER BY dc.headcount DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,cte
"Using a CTE, identify patients with more than 3 appointments and list their diagnoses.","WITH frequent_patients AS (
SELECT patient_id, COUNT(*) AS visit_count
FROM appointments
GROUP BY patient_id
HAVING COUNT(*) > 3
)
SELECT p.name, a.appointment_date, a.diagnosis
FROM appointments a
JOIN patients p ON a.patient_id = p.patient_id
WHERE a.patient_id IN (SELECT patient_id FROM frequent_patients)
ORDER BY p.name, a.appointment_date;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,cte
"Using a CTE, find users who converted within 7 days of signup.","WITH conversion_lag AS (
SELECT u.user_id, u.username, u.signup_date,
MIN(c.event_date) AS first_conversion
FROM users u
JOIN conversions c ON u.user_id = c.user_id
GROUP BY u.user_id, u.username, u.signup_date
)
SELECT username, signup_date, first_conversion,
first_conversion - signup_date AS days_to_convert
FROM conversion_lag
WHERE first_conversion - signup_date <= 7
ORDER BY days_to_convert;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,cte
"Using a CTE, find which warehouses hold items below their reorder point and flag urgency.","WITH low_stock AS (
SELECT s.warehouse_id, s.item_id, s.quantity,
i.reorder_point, i.name AS item_name,
i.reorder_point - s.quantity AS deficit
FROM stock s
JOIN items i ON s.item_id = i.item_id
WHERE s.quantity < i.reorder_point
)
SELECT w.name AS warehouse, ls.item_name, ls.quantity, ls.reorder_point, ls.deficit,
CASE WHEN ls.deficit > ls.reorder_point * 0.5 THEN 'CRITICAL' ELSE 'LOW' END AS urgency
FROM low_stock ls
JOIN warehouses w ON ls.warehouse_id = w.warehouse_id
ORDER BY ls.deficit DESC;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,cte
Rank products by price within each category using a window function.,"SELECT name, category, price,
RANK() OVER (PARTITION BY category ORDER BY price DESC) AS price_rank
FROM products;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,window
"Calculate a running total of order revenue per customer, ordered by date.","SELECT customer_id, order_date, total_amount,
SUM(total_amount) OVER (PARTITION BY customer_id ORDER BY order_date) AS running_total
FROM orders;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,window
Show each employee's salary and how it compares to the department average.,"SELECT name, salary, department_id,
AVG(salary) OVER (PARTITION BY department_id) AS dept_avg,
salary - AVG(salary) OVER (PARTITION BY department_id) AS diff_from_avg
FROM employees;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,window
Rank doctors by appointment count per specialty using DENSE_RANK.,"SELECT d.name, d.specialty,
COUNT(a.appointment_id) AS appt_count,
DENSE_RANK() OVER (PARTITION BY d.specialty ORDER BY COUNT(a.appointment_id) DESC) AS rank_in_specialty
FROM doctors d
LEFT JOIN appointments a ON d.doctor_id = a.doctor_id
GROUP BY d.doctor_id, d.name, d.specialty;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,window
Show each user's cumulative revenue from conversions over time.,"SELECT user_id, event_date, revenue,
SUM(revenue) OVER (PARTITION BY user_id ORDER BY event_date) AS cumulative_revenue
FROM conversions;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,window
"For each event, show the previous event type for the same user.","SELECT user_id, event_date, event_type,
LAG(event_type) OVER (PARTITION BY user_id ORDER BY event_date) AS prev_event_type
FROM events;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,window
Show each item's movement quantity and its percentage of total movements for that item.,"SELECT item_id, movement_date, quantity,
ROUND(100.0 * quantity / SUM(quantity) OVER (PARTITION BY item_id), 2) AS pct_of_item_total
FROM movements
WHERE movement_type = 'receipt'
ORDER BY item_id, movement_date;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,window
Find the second highest salary in each department.,"SELECT department_id, name, salary
FROM (
SELECT department_id, name, salary,
DENSE_RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rnk
FROM employees
) ranked
WHERE rnk = 2;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,window
"List all customers and their total number of orders, including customers with no orders.","SELECT c.name, COUNT(o.order_id) AS order_count
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_id, c.name
ORDER BY order_count DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
"List all doctors and the number of patients they have seen, including doctors with no appointments.","SELECT d.name, COUNT(a.appointment_id) AS patient_count
FROM doctors d
LEFT JOIN appointments a ON d.doctor_id = a.doctor_id
GROUP BY d.doctor_id, d.name
ORDER BY patient_count DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
"Show all projects and the number of employees assigned, including unassigned projects.","SELECT p.name, COUNT(a.employee_id) AS assigned_employees
FROM projects p
LEFT JOIN assignments a ON p.project_id = a.project_id
GROUP BY p.project_id, p.name
ORDER BY assigned_employees DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,join
How many orders were placed each day of the week on average?,"SELECT EXTRACT(DOW FROM order_date) AS day_of_week,
COUNT(*) / COUNT(DISTINCT DATE_TRUNC('week', order_date)) AS avg_orders_per_week
FROM orders
GROUP BY day_of_week
ORDER BY day_of_week;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
What is the average time between a patient's first and most recent appointment?,"SELECT patient_id,
MIN(appointment_date) AS first_visit,
MAX(appointment_date) AS last_visit,
MAX(appointment_date) - MIN(appointment_date) AS days_span
FROM appointments
GROUP BY patient_id
HAVING COUNT(*) > 1
ORDER BY days_span DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,aggregate
How many new users signed up per week in the last 90 days?,"SELECT DATE_TRUNC('week', signup_date) AS week_start, COUNT(*) AS signups
FROM users
WHERE signup_date >= CURRENT_DATE - INTERVAL '90 days'
GROUP BY week_start
ORDER BY week_start;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,aggregate
Find all products whose name starts with 'Pro'.,SELECT * FROM products WHERE name LIKE 'Pro%';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Find all customers whose email domain is 'gmail.com'.,SELECT * FROM customers WHERE email LIKE '%@gmail.com';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Find all patients whose name contains 'John'.,SELECT * FROM patients WHERE name ILIKE '%john%';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
"Categorize orders as 'small', 'medium', or 'large' based on total amount.","SELECT order_id, total_amount,
CASE
WHEN total_amount < 50 THEN 'small'
WHEN total_amount < 200 THEN 'medium'
ELSE 'large'
END AS order_size
FROM orders;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,select
"Classify employees as 'junior', 'mid-level', or 'senior' based on salary.","SELECT name, salary,
CASE
WHEN salary < 50000 THEN 'junior'
WHEN salary < 100000 THEN 'mid-level'
ELSE 'senior'
END AS seniority_level
FROM employees;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,select
"Flag inventory items as 'out of stock', 'low', or 'sufficient'.","SELECT i.name, s.quantity, i.reorder_point,
CASE
WHEN s.quantity = 0 THEN 'out_of_stock'
WHEN s.quantity < i.reorder_point THEN 'low'
ELSE 'sufficient'
END AS stock_status
FROM stock s
JOIN items i ON s.item_id = i.item_id;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,select
What percentage of total revenue does each customer represent?,"SELECT c.name,
SUM(o.total_amount) AS customer_revenue,
ROUND(100.0 * SUM(o.total_amount) / (SELECT SUM(total_amount) FROM orders), 2) AS pct_of_total
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.name
ORDER BY customer_revenue DESC;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
Find the specialty with the highest average patient age.,"SELECT d.specialty, AVG(EXTRACT(YEAR FROM AGE(p.date_of_birth))) AS avg_patient_age
FROM appointments a
JOIN doctors d ON a.doctor_id = d.doctor_id
JOIN patients p ON a.patient_id = p.patient_id
GROUP BY d.specialty
ORDER BY avg_patient_age DESC
LIMIT 1;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,aggregate
Which campaigns had the highest ROI (revenue per conversion)?,"SELECT campaign_id,
COUNT(*) AS conversions,
SUM(revenue) AS total_revenue,
AVG(revenue) AS avg_revenue_per_conversion
FROM conversions
GROUP BY campaign_id
ORDER BY avg_revenue_per_conversion DESC;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,aggregate
Find employees who are assigned to more than 2 active projects.,"SELECT e.name, COUNT(DISTINCT a.project_id) AS project_count
FROM employees e
JOIN assignments a ON e.employee_id = a.employee_id
JOIN projects p ON a.project_id = p.project_id
WHERE p.end_date >= CURRENT_DATE
GROUP BY e.employee_id, e.name
HAVING COUNT(DISTINCT a.project_id) > 2
ORDER BY project_count DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,subquery
Which item SKU has the highest total outbound movement in the last 30 days?,"SELECT i.sku, i.name, SUM(m.quantity) AS outbound_qty
FROM movements m
JOIN items i ON m.item_id = i.item_id
WHERE m.movement_type = 'shipment'
AND m.movement_date >= CURRENT_DATE - INTERVAL '30 days'
GROUP BY i.sku, i.name
ORDER BY outbound_qty DESC
LIMIT 1;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,aggregate
Find all employees and their manager's name.,"SELECT e.name AS employee, m.name AS manager
FROM employees e
LEFT JOIN employees m ON e.manager_id = m.employee_id
ORDER BY m.name NULLS LAST, e.name;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,join
Find pairs of employees in the same department who earn within 5000 of each other.,"SELECT a.name AS employee1, b.name AS employee2, a.salary AS sal1, b.salary AS sal2
FROM employees a
JOIN employees b ON a.department_id = b.department_id
AND a.employee_id < b.employee_id
AND ABS(a.salary - b.salary) <= 5000
ORDER BY a.name;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,join
Find customers who have ordered every product in the 'Electronics' category.,"SELECT c.name
FROM customers c
WHERE NOT EXISTS (
SELECT 1 FROM products p
WHERE p.category = 'Electronics'
AND NOT EXISTS (
SELECT 1 FROM orders o
JOIN order_items oi ON o.order_id = oi.order_id
WHERE o.customer_id = c.customer_id
AND oi.product_id = p.product_id
)
);"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
Find patients who have seen at least one doctor in every specialty at the hospital.,"SELECT p.name
FROM patients p
WHERE NOT EXISTS (
SELECT 1 FROM doctors d
WHERE NOT EXISTS (
SELECT 1 FROM appointments a
WHERE a.patient_id = p.patient_id AND a.doctor_id = d.doctor_id
)
);"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,subquery
Insert a new customer record.,"INSERT INTO customers (name, email, city, country, created_at, total_spent)
VALUES ('Alice Johnson', 'alice@example.com', 'London', 'United Kingdom', CURRENT_DATE, 0);"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,select
Update the status of all orders older than 30 days that are still 'pending' to 'cancelled'.,"UPDATE orders
SET status = 'cancelled'
WHERE status = 'pending'
AND order_date < CURRENT_DATE - INTERVAL '30 days';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,select
Delete all sessions that ended more than one year ago.,"DELETE FROM sessions
WHERE end_time < NOW() - INTERVAL '1 year';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,select
How many customers are from Germany?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Germany';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from France?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'France';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from United Kingdom?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'United Kingdom';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from Canada?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Canada';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from Australia?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Australia';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from Japan?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Japan';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from Brazil?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Brazil';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from India?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'India';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from Spain?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Spain';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many customers are from Italy?,SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Italy';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from 'pending' orders?,SELECT SUM(total_amount) AS revenue FROM orders WHERE status = 'pending';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
List all 'pending' orders with customer name.,"SELECT o.order_id, c.name, o.order_date, o.total_amount
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
WHERE o.status = 'pending';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
What is the total revenue from 'shipped' orders?,SELECT SUM(total_amount) AS revenue FROM orders WHERE status = 'shipped';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
List all 'shipped' orders with customer name.,"SELECT o.order_id, c.name, o.order_date, o.total_amount
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
WHERE o.status = 'shipped';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
What is the total revenue from 'cancelled' orders?,SELECT SUM(total_amount) AS revenue FROM orders WHERE status = 'cancelled';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
List all 'cancelled' orders with customer name.,"SELECT o.order_id, c.name, o.order_date, o.total_amount
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
WHERE o.status = 'cancelled';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
What is the total revenue from 'delivered' orders?,SELECT SUM(total_amount) AS revenue FROM orders WHERE status = 'delivered';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
List all 'delivered' orders with customer name.,"SELECT o.order_id, c.name, o.order_date, o.total_amount
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
WHERE o.status = 'delivered';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
What is the total revenue from 'processing' orders?,SELECT SUM(total_amount) AS revenue FROM orders WHERE status = 'processing';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
List all 'processing' orders with customer name.,"SELECT o.order_id, c.name, o.order_date, o.total_amount
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
WHERE o.status = 'processing';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
How many products are in the 'Electronics' category?,SELECT COUNT(*) FROM products WHERE category = 'Electronics';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average price of 'Electronics' products?,SELECT AVG(price) AS avg_price FROM products WHERE category = 'Electronics';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from 'Electronics' category products?,"SELECT SUM(oi.quantity * oi.unit_price) AS revenue
FROM order_items oi JOIN products p ON oi.product_id = p.product_id
WHERE p.category = 'Electronics';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
How many products are in the 'Clothing' category?,SELECT COUNT(*) FROM products WHERE category = 'Clothing';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average price of 'Clothing' products?,SELECT AVG(price) AS avg_price FROM products WHERE category = 'Clothing';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from 'Clothing' category products?,"SELECT SUM(oi.quantity * oi.unit_price) AS revenue
FROM order_items oi JOIN products p ON oi.product_id = p.product_id
WHERE p.category = 'Clothing';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
How many products are in the 'Books' category?,SELECT COUNT(*) FROM products WHERE category = 'Books';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average price of 'Books' products?,SELECT AVG(price) AS avg_price FROM products WHERE category = 'Books';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from 'Books' category products?,"SELECT SUM(oi.quantity * oi.unit_price) AS revenue
FROM order_items oi JOIN products p ON oi.product_id = p.product_id
WHERE p.category = 'Books';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
How many products are in the 'Sports' category?,SELECT COUNT(*) FROM products WHERE category = 'Sports';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average price of 'Sports' products?,SELECT AVG(price) AS avg_price FROM products WHERE category = 'Sports';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from 'Sports' category products?,"SELECT SUM(oi.quantity * oi.unit_price) AS revenue
FROM order_items oi JOIN products p ON oi.product_id = p.product_id
WHERE p.category = 'Sports';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
How many products are in the 'Home' category?,SELECT COUNT(*) FROM products WHERE category = 'Home';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average price of 'Home' products?,SELECT AVG(price) AS avg_price FROM products WHERE category = 'Home';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from 'Home' category products?,"SELECT SUM(oi.quantity * oi.unit_price) AS revenue
FROM order_items oi JOIN products p ON oi.product_id = p.product_id
WHERE p.category = 'Home';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
How many products are in the 'Beauty' category?,SELECT COUNT(*) FROM products WHERE category = 'Beauty';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the average price of 'Beauty' products?,SELECT AVG(price) AS avg_price FROM products WHERE category = 'Beauty';," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
What is the total revenue from 'Beauty' category products?,"SELECT SUM(oi.quantity * oi.unit_price) AS revenue
FROM order_items oi JOIN products p ON oi.product_id = p.product_id
WHERE p.category = 'Beauty';"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
What is the total revenue in 2022?,SELECT SUM(total_amount) AS revenue FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2022;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many orders were placed in 2022?,SELECT COUNT(*) AS order_count FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2022;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
Which month had the most orders in 2022?,"SELECT EXTRACT(MONTH FROM order_date) AS month, COUNT(*) AS orders
FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2022
GROUP BY month ORDER BY orders DESC LIMIT 1;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
What is the total revenue in 2023?,SELECT SUM(total_amount) AS revenue FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2023;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many orders were placed in 2023?,SELECT COUNT(*) AS order_count FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2023;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
Which month had the most orders in 2023?,"SELECT EXTRACT(MONTH FROM order_date) AS month, COUNT(*) AS orders
FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2023
GROUP BY month ORDER BY orders DESC LIMIT 1;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
What is the total revenue in 2024?,SELECT SUM(total_amount) AS revenue FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2024;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
How many orders were placed in 2024?,SELECT COUNT(*) AS order_count FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2024;," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,aggregate
Which month had the most orders in 2024?,"SELECT EXTRACT(MONTH FROM order_date) AS month, COUNT(*) AS orders
FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2024
GROUP BY month ORDER BY orders DESC LIMIT 1;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
List the top 5 best-selling products by total quantity sold.,"SELECT p.name, SUM(oi.quantity) AS total_sold
FROM order_items oi JOIN products p ON oi.product_id = p.product_id
GROUP BY p.name ORDER BY total_sold DESC LIMIT 5;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
Find the average number of items per order.,"SELECT AVG(item_count) AS avg_items_per_order
FROM (SELECT order_id, SUM(quantity) AS item_count FROM order_items GROUP BY order_id) sub;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,subquery
Find the customer who placed the most recent order.,"SELECT c.name, MAX(o.order_date) AS last_order
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
GROUP BY c.customer_id, c.name ORDER BY last_order DESC LIMIT 1;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,aggregate
What fraction of customers have placed at least one order?,"SELECT ROUND(100.0 * COUNT(DISTINCT o.customer_id) / COUNT(DISTINCT c.customer_id), 2) AS pct_customers_ordered
FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
List the 10 most recent orders with customer name and status.,"SELECT o.order_id, c.name, o.order_date, o.status, o.total_amount
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
ORDER BY o.order_date DESC LIMIT 10;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,easy,join
Which supplier has the highest average product rating via order volume?,"SELECT s.name AS supplier, SUM(oi.quantity) AS units_sold
FROM order_items oi
JOIN products p ON oi.product_id = p.product_id
JOIN suppliers s ON p.supplier_id = s.supplier_id
GROUP BY s.name ORDER BY units_sold DESC LIMIT 1;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,join
Find all orders where the shipping city differs from the customer's city.,"SELECT o.order_id, c.city AS home_city, o.shipping_city
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
WHERE c.city <> o.shipping_city;"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,medium,join
List all products with no sales in the last 60 days.,"SELECT p.name FROM products p
WHERE p.product_id NOT IN (
SELECT DISTINCT oi.product_id FROM order_items oi
JOIN orders o ON oi.order_id = o.order_id
WHERE o.order_date >= CURRENT_DATE - INTERVAL '60 days'
);"," customers(customer_id, name, email, city, country, created_at, total_spent)
orders(order_id, customer_id, order_date, status, total_amount, shipping_city)
order_items(item_id, order_id, product_id, quantity, unit_price)
products(product_id, name, category, price, stock_quantity, supplier_id)
suppliers(supplier_id, name, country, rating)",ecommerce,hard,subquery
How many doctors specialize in Cardiology?,SELECT COUNT(*) FROM doctors WHERE specialty = 'Cardiology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
List all Cardiology doctors and the hospital they work at.,"SELECT d.name, h.name AS hospital FROM doctors d
JOIN hospitals h ON d.hospital_id = h.hospital_id
WHERE d.specialty = 'Cardiology';"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
What is the average years of experience for Cardiology doctors?,SELECT AVG(years_experience) FROM doctors WHERE specialty = 'Cardiology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
How many doctors specialize in Neurology?,SELECT COUNT(*) FROM doctors WHERE specialty = 'Neurology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
List all Neurology doctors and the hospital they work at.,"SELECT d.name, h.name AS hospital FROM doctors d
JOIN hospitals h ON d.hospital_id = h.hospital_id
WHERE d.specialty = 'Neurology';"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
What is the average years of experience for Neurology doctors?,SELECT AVG(years_experience) FROM doctors WHERE specialty = 'Neurology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
How many doctors specialize in Orthopedics?,SELECT COUNT(*) FROM doctors WHERE specialty = 'Orthopedics';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
List all Orthopedics doctors and the hospital they work at.,"SELECT d.name, h.name AS hospital FROM doctors d
JOIN hospitals h ON d.hospital_id = h.hospital_id
WHERE d.specialty = 'Orthopedics';"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
What is the average years of experience for Orthopedics doctors?,SELECT AVG(years_experience) FROM doctors WHERE specialty = 'Orthopedics';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
How many doctors specialize in Pediatrics?,SELECT COUNT(*) FROM doctors WHERE specialty = 'Pediatrics';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
List all Pediatrics doctors and the hospital they work at.,"SELECT d.name, h.name AS hospital FROM doctors d
JOIN hospitals h ON d.hospital_id = h.hospital_id
WHERE d.specialty = 'Pediatrics';"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
What is the average years of experience for Pediatrics doctors?,SELECT AVG(years_experience) FROM doctors WHERE specialty = 'Pediatrics';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
How many doctors specialize in Oncology?,SELECT COUNT(*) FROM doctors WHERE specialty = 'Oncology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
List all Oncology doctors and the hospital they work at.,"SELECT d.name, h.name AS hospital FROM doctors d
JOIN hospitals h ON d.hospital_id = h.hospital_id
WHERE d.specialty = 'Oncology';"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
What is the average years of experience for Oncology doctors?,SELECT AVG(years_experience) FROM doctors WHERE specialty = 'Oncology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
How many doctors specialize in Dermatology?,SELECT COUNT(*) FROM doctors WHERE specialty = 'Dermatology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
List all Dermatology doctors and the hospital they work at.,"SELECT d.name, h.name AS hospital FROM doctors d
JOIN hospitals h ON d.hospital_id = h.hospital_id
WHERE d.specialty = 'Dermatology';"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
What is the average years of experience for Dermatology doctors?,SELECT AVG(years_experience) FROM doctors WHERE specialty = 'Dermatology';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
How many male patients are there?,SELECT COUNT(*) FROM patients WHERE gender = 'M';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
What is the most common diagnosis among male patients?,"SELECT a.diagnosis, COUNT(*) AS cnt
FROM appointments a JOIN patients p ON a.patient_id = p.patient_id
WHERE p.gender = 'M'
GROUP BY a.diagnosis ORDER BY cnt DESC LIMIT 1;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,aggregate
How many female patients are there?,SELECT COUNT(*) FROM patients WHERE gender = 'F';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
What is the most common diagnosis among female patients?,"SELECT a.diagnosis, COUNT(*) AS cnt
FROM appointments a JOIN patients p ON a.patient_id = p.patient_id
WHERE p.gender = 'F'
GROUP BY a.diagnosis ORDER BY cnt DESC LIMIT 1;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,aggregate
List all patients with 'private' insurance.,SELECT * FROM patients WHERE insurance_type = 'private';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
List all patients with 'public' insurance.,SELECT * FROM patients WHERE insurance_type = 'public';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
List all patients with 'none' insurance.,SELECT * FROM patients WHERE insurance_type = 'none';," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,select
Find the most prescribed medication.,"SELECT medication, COUNT(*) AS prescription_count
FROM prescriptions GROUP BY medication ORDER BY prescription_count DESC LIMIT 1;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
What is the average prescription duration in days?,SELECT AVG(duration_days) AS avg_duration FROM prescriptions;," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
Find patients who have had appointments cancelled more than twice.,"SELECT p.name, COUNT(*) AS cancellations
FROM appointments a JOIN patients p ON a.patient_id = p.patient_id
WHERE a.status = 'cancelled'
GROUP BY p.patient_id, p.name HAVING COUNT(*) > 2;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,aggregate
List all hospitals and the number of doctors they employ.,"SELECT h.name, COUNT(d.doctor_id) AS doctor_count
FROM hospitals h LEFT JOIN doctors d ON h.hospital_id = d.hospital_id
GROUP BY h.name ORDER BY doctor_count DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,join
Find the doctor who has the most unique patients.,"SELECT d.name, COUNT(DISTINCT a.patient_id) AS unique_patients
FROM doctors d JOIN appointments a ON d.doctor_id = a.doctor_id
GROUP BY d.doctor_id, d.name ORDER BY unique_patients DESC LIMIT 1;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,medium,aggregate
What is the average age of patients at first appointment?,"SELECT AVG(EXTRACT(YEAR FROM AGE(first_appt, p.date_of_birth))) AS avg_age_at_first_appt
FROM patients p
JOIN (
SELECT patient_id, MIN(appointment_date) AS first_appt
FROM appointments GROUP BY patient_id
) fa ON p.patient_id = fa.patient_id;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,subquery
"List prescriptions longer than the average duration, with patient and doctor names.","SELECT pr.medication, pr.duration_days, p.name AS patient, d.name AS doctor
FROM prescriptions pr
JOIN appointments a ON pr.appointment_id = a.appointment_id
JOIN patients p ON a.patient_id = p.patient_id
JOIN doctors d ON a.doctor_id = d.doctor_id
WHERE pr.duration_days > (SELECT AVG(duration_days) FROM prescriptions)
ORDER BY pr.duration_days DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,subquery
Which city has the most patients?,"SELECT city, COUNT(*) AS patient_count FROM patients GROUP BY city ORDER BY patient_count DESC LIMIT 1;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,easy,aggregate
Show each specialty and the total number of unique patients seen per year.,"SELECT d.specialty, EXTRACT(YEAR FROM a.appointment_date) AS year,
COUNT(DISTINCT a.patient_id) AS unique_patients
FROM appointments a JOIN doctors d ON a.doctor_id = d.doctor_id
GROUP BY d.specialty, year ORDER BY year, unique_patients DESC;"," patients(patient_id, name, date_of_birth, gender, city, insurance_type)
doctors(doctor_id, name, specialty, hospital_id, years_experience)
appointments(appointment_id, patient_id, doctor_id, appointment_date, status, diagnosis)
hospitals(hospital_id, name, city, beds, rating)
prescriptions(prescription_id, appointment_id, medication, dosage, duration_days)",healthcare,hard,aggregate
How many users are on the 'free' plan?,SELECT COUNT(*) FROM users WHERE plan = 'free';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the total revenue from 'free' plan users?,"SELECT SUM(c.revenue) FROM conversions c
JOIN users u ON c.user_id = u.user_id WHERE u.plan = 'free';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,join
How many users are on the 'basic' plan?,SELECT COUNT(*) FROM users WHERE plan = 'basic';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the total revenue from 'basic' plan users?,"SELECT SUM(c.revenue) FROM conversions c
JOIN users u ON c.user_id = u.user_id WHERE u.plan = 'basic';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,join
How many users are on the 'pro' plan?,SELECT COUNT(*) FROM users WHERE plan = 'pro';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the total revenue from 'pro' plan users?,"SELECT SUM(c.revenue) FROM conversions c
JOIN users u ON c.user_id = u.user_id WHERE u.plan = 'pro';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,join
How many users are on the 'enterprise' plan?,SELECT COUNT(*) FROM users WHERE plan = 'enterprise';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the total revenue from 'enterprise' plan users?,"SELECT SUM(c.revenue) FROM conversions c
JOIN users u ON c.user_id = u.user_id WHERE u.plan = 'enterprise';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,join
How many sessions were from mobile?,SELECT COUNT(*) FROM sessions WHERE device = 'mobile';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the average session duration on mobile?,"SELECT AVG(EXTRACT(EPOCH FROM (end_time - start_time))) AS avg_duration_seconds
FROM sessions WHERE device = 'mobile';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many sessions were from desktop?,SELECT COUNT(*) FROM sessions WHERE device = 'desktop';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the average session duration on desktop?,"SELECT AVG(EXTRACT(EPOCH FROM (end_time - start_time))) AS avg_duration_seconds
FROM sessions WHERE device = 'desktop';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many sessions were from tablet?,SELECT COUNT(*) FROM sessions WHERE device = 'tablet';," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the average session duration on tablet?,"SELECT AVG(EXTRACT(EPOCH FROM (end_time - start_time))) AS avg_duration_seconds
FROM sessions WHERE device = 'tablet';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many 'page_view' events occurred in the last 30 days?,"SELECT COUNT(*) FROM events
WHERE event_type = 'page_view' AND event_date >= CURRENT_DATE - INTERVAL '30 days';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many 'click' events occurred in the last 30 days?,"SELECT COUNT(*) FROM events
WHERE event_type = 'click' AND event_date >= CURRENT_DATE - INTERVAL '30 days';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many 'signup' events occurred in the last 30 days?,"SELECT COUNT(*) FROM events
WHERE event_type = 'signup' AND event_date >= CURRENT_DATE - INTERVAL '30 days';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many 'purchase' events occurred in the last 30 days?,"SELECT COUNT(*) FROM events
WHERE event_type = 'purchase' AND event_date >= CURRENT_DATE - INTERVAL '30 days';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many 'logout' events occurred in the last 30 days?,"SELECT COUNT(*) FROM events
WHERE event_type = 'logout' AND event_date >= CURRENT_DATE - INTERVAL '30 days';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
How many 'search' events occurred in the last 30 days?,"SELECT COUNT(*) FROM events
WHERE event_type = 'search' AND event_date >= CURRENT_DATE - INTERVAL '30 days';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
Find the top 5 most visited pages.,"SELECT page, COUNT(*) AS views FROM events WHERE event_type = 'page_view'
GROUP BY page ORDER BY views DESC LIMIT 5;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,easy,aggregate
What is the daily active user count for the last 7 days?,"SELECT event_date, COUNT(DISTINCT user_id) AS dau
FROM events
WHERE event_date >= CURRENT_DATE - INTERVAL '7 days'
GROUP BY event_date ORDER BY event_date;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,aggregate
Calculate the 7-day rolling average of daily signups.,"SELECT signup_date, COUNT(*) AS daily_signups,
AVG(COUNT(*)) OVER (ORDER BY signup_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS rolling_7d_avg
FROM users
GROUP BY signup_date ORDER BY signup_date;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,window
Find users who have not logged any event in the past 30 days.,"SELECT u.user_id, u.username
FROM users u WHERE u.user_id NOT IN (
SELECT DISTINCT user_id FROM events
WHERE event_date >= CURRENT_DATE - INTERVAL '30 days'
);"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,subquery
What is the conversion rate (conversions / total users) per plan?,"SELECT u.plan,
COUNT(DISTINCT c.user_id) AS converters,
COUNT(DISTINCT u.user_id) AS total_users,
ROUND(100.0 * COUNT(DISTINCT c.user_id) / NULLIF(COUNT(DISTINCT u.user_id), 0), 2) AS conversion_rate_pct
FROM users u LEFT JOIN conversions c ON u.user_id = c.user_id
GROUP BY u.plan ORDER BY conversion_rate_pct DESC;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,join
Show sessions that started and ended on different days.,"SELECT * FROM sessions
WHERE DATE(start_time) <> DATE(end_time);"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,select
Find the browser with the highest average session duration.,"SELECT browser,
AVG(EXTRACT(EPOCH FROM (end_time - start_time))) AS avg_sec
FROM sessions GROUP BY browser ORDER BY avg_sec DESC LIMIT 1;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,medium,aggregate
Identify users who made their first conversion within 24 hours of signup.,"WITH first_conv AS (
SELECT user_id, MIN(event_date) AS first_conv_date FROM conversions GROUP BY user_id
)
SELECT u.username, u.signup_date, fc.first_conv_date
FROM users u JOIN first_conv fc ON u.user_id = fc.user_id
WHERE fc.first_conv_date <= u.signup_date + INTERVAL '1 day';"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,cte
"Rank users by total revenue generated, partitioned by plan.","SELECT u.username, u.plan, SUM(c.revenue) AS total_revenue,
RANK() OVER (PARTITION BY u.plan ORDER BY SUM(c.revenue) DESC) AS rank_in_plan
FROM users u JOIN conversions c ON u.user_id = c.user_id
GROUP BY u.username, u.plan;"," events(event_id, user_id, event_type, event_date, page, session_id, duration_seconds)
users(user_id, username, signup_date, plan, country, is_active)
sessions(session_id, user_id, start_time, end_time, device, browser)
pages(page_id, url, title, category, created_at)
conversions(conversion_id, user_id, event_date, revenue, campaign_id)",analytics,hard,window
Find all employees with a performance rating of 1.,"SELECT e.name, pr.review_year, pr.bonus
FROM employees e JOIN performance_reviews pr ON e.employee_id = pr.employee_id
WHERE pr.rating = 1;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,join
Find all employees with a performance rating of 2.,"SELECT e.name, pr.review_year, pr.bonus
FROM employees e JOIN performance_reviews pr ON e.employee_id = pr.employee_id
WHERE pr.rating = 2;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,join
Find all employees with a performance rating of 3.,"SELECT e.name, pr.review_year, pr.bonus
FROM employees e JOIN performance_reviews pr ON e.employee_id = pr.employee_id
WHERE pr.rating = 3;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,join
Find all employees with a performance rating of 4.,"SELECT e.name, pr.review_year, pr.bonus
FROM employees e JOIN performance_reviews pr ON e.employee_id = pr.employee_id
WHERE pr.rating = 4;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,join
Find all employees with a performance rating of 5.,"SELECT e.name, pr.review_year, pr.bonus
FROM employees e JOIN performance_reviews pr ON e.employee_id = pr.employee_id
WHERE pr.rating = 5;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,join
What is the average bonus paid in 2022?,SELECT AVG(bonus) FROM performance_reviews WHERE review_year = 2022;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,aggregate
Which department had the highest average rating in 2022?,"SELECT d.name, AVG(pr.rating) AS avg_rating
FROM performance_reviews pr
JOIN employees e ON pr.employee_id = e.employee_id
JOIN departments d ON e.department_id = d.department_id
WHERE pr.review_year = 2022
GROUP BY d.name ORDER BY avg_rating DESC LIMIT 1;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
What is the average bonus paid in 2023?,SELECT AVG(bonus) FROM performance_reviews WHERE review_year = 2023;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,aggregate
Which department had the highest average rating in 2023?,"SELECT d.name, AVG(pr.rating) AS avg_rating
FROM performance_reviews pr
JOIN employees e ON pr.employee_id = e.employee_id
JOIN departments d ON e.department_id = d.department_id
WHERE pr.review_year = 2023
GROUP BY d.name ORDER BY avg_rating DESC LIMIT 1;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
What is the average bonus paid in 2024?,SELECT AVG(bonus) FROM performance_reviews WHERE review_year = 2024;," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,aggregate
Which department had the highest average rating in 2024?,"SELECT d.name, AVG(pr.rating) AS avg_rating
FROM performance_reviews pr
JOIN employees e ON pr.employee_id = e.employee_id
JOIN departments d ON e.department_id = d.department_id
WHERE pr.review_year = 2024
GROUP BY d.name ORDER BY avg_rating DESC LIMIT 1;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
Find the employee with the longest tenure.,"SELECT name, hire_date, CURRENT_DATE - hire_date AS tenure_days
FROM employees ORDER BY hire_date ASC LIMIT 1;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,select
List all employees who have never received a bonus.,"SELECT e.name FROM employees e
WHERE e.employee_id NOT IN (
SELECT employee_id FROM performance_reviews WHERE bonus > 0
);"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,subquery
Find departments where every employee earns above 60000.,"SELECT d.name FROM departments d
WHERE NOT EXISTS (
SELECT 1 FROM employees e
WHERE e.department_id = d.department_id AND e.salary <= 60000
);"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,subquery
List the top 3 highest-paid employees per department.,"SELECT department_id, name, salary
FROM (
SELECT department_id, name, salary,
ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rn
FROM employees
) t WHERE rn <= 3;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,window
Find all employees who changed departments in the last year.,"SELECT e.name, e.department_id, e.hire_date
FROM employees e
WHERE e.hire_date >= CURRENT_DATE - INTERVAL '1 year';"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,easy,select
What is the total project budget per department?,"SELECT d.name, SUM(p.budget) AS total_budget
FROM projects p JOIN departments d ON p.department_id = d.department_id
GROUP BY d.name ORDER BY total_budget DESC;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
List all projects that are over budget relative to the department budget.,"SELECT p.name AS project_name, p.budget AS project_budget, d.budget AS dept_budget
FROM projects p JOIN departments d ON p.department_id = d.department_id
WHERE p.budget > d.budget;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,join
Find employees assigned to the most hours per week across all projects.,"SELECT e.name, SUM(a.hours_per_week) AS total_hours
FROM employees e JOIN assignments a ON e.employee_id = a.employee_id
GROUP BY e.employee_id, e.name ORDER BY total_hours DESC LIMIT 5;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,medium,aggregate
Calculate year-over-year average bonus change by department.,"WITH dept_bonus AS (
SELECT d.name AS dept, pr.review_year,
AVG(pr.bonus) AS avg_bonus
FROM performance_reviews pr
JOIN employees e ON pr.employee_id = e.employee_id
JOIN departments d ON e.department_id = d.department_id
GROUP BY d.name, pr.review_year
)
SELECT dept, review_year, avg_bonus,
avg_bonus - LAG(avg_bonus) OVER (PARTITION BY dept ORDER BY review_year) AS yoy_change
FROM dept_bonus ORDER BY dept, review_year;"," employees(employee_id, name, department_id, manager_id, hire_date, salary, city)
departments(department_id, name, location, budget, head_count)
projects(project_id, name, department_id, start_date, end_date, budget)
assignments(assignment_id, employee_id, project_id, role, hours_per_week)
performance_reviews(review_id, employee_id, review_year, rating, bonus)",hr,hard,cte
How many 'receipt' movements happened this month?,"SELECT COUNT(*) FROM movements
WHERE movement_type = 'receipt' AND DATE_TRUNC('month', movement_date) = DATE_TRUNC('month', CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
What is the total quantity moved as 'receipt' this year?,"SELECT SUM(quantity) FROM movements
WHERE movement_type = 'receipt' AND EXTRACT(YEAR FROM movement_date) = EXTRACT(YEAR FROM CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
How many 'shipment' movements happened this month?,"SELECT COUNT(*) FROM movements
WHERE movement_type = 'shipment' AND DATE_TRUNC('month', movement_date) = DATE_TRUNC('month', CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
What is the total quantity moved as 'shipment' this year?,"SELECT SUM(quantity) FROM movements
WHERE movement_type = 'shipment' AND EXTRACT(YEAR FROM movement_date) = EXTRACT(YEAR FROM CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
How many 'adjustment' movements happened this month?,"SELECT COUNT(*) FROM movements
WHERE movement_type = 'adjustment' AND DATE_TRUNC('month', movement_date) = DATE_TRUNC('month', CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
What is the total quantity moved as 'adjustment' this year?,"SELECT SUM(quantity) FROM movements
WHERE movement_type = 'adjustment' AND EXTRACT(YEAR FROM movement_date) = EXTRACT(YEAR FROM CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
How many 'return' movements happened this month?,"SELECT COUNT(*) FROM movements
WHERE movement_type = 'return' AND DATE_TRUNC('month', movement_date) = DATE_TRUNC('month', CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
What is the total quantity moved as 'return' this year?,"SELECT SUM(quantity) FROM movements
WHERE movement_type = 'return' AND EXTRACT(YEAR FROM movement_date) = EXTRACT(YEAR FROM CURRENT_DATE);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,aggregate
List all items in the 'Raw Materials' category.,SELECT * FROM items WHERE category = 'Raw Materials';," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
What is the total stock value for 'Raw Materials' items?,"SELECT SUM(s.quantity * i.unit_cost) AS total_value
FROM stock s JOIN items i ON s.item_id = i.item_id
WHERE i.category = 'Raw Materials';"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,join
List all items in the 'Finished Goods' category.,SELECT * FROM items WHERE category = 'Finished Goods';," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
What is the total stock value for 'Finished Goods' items?,"SELECT SUM(s.quantity * i.unit_cost) AS total_value
FROM stock s JOIN items i ON s.item_id = i.item_id
WHERE i.category = 'Finished Goods';"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,join
List all items in the 'Spare Parts' category.,SELECT * FROM items WHERE category = 'Spare Parts';," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
What is the total stock value for 'Spare Parts' items?,"SELECT SUM(s.quantity * i.unit_cost) AS total_value
FROM stock s JOIN items i ON s.item_id = i.item_id
WHERE i.category = 'Spare Parts';"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,join
List all items in the 'Packaging' category.,SELECT * FROM items WHERE category = 'Packaging';," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
What is the total stock value for 'Packaging' items?,"SELECT SUM(s.quantity * i.unit_cost) AS total_value
FROM stock s JOIN items i ON s.item_id = i.item_id
WHERE i.category = 'Packaging';"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,join
List all items in the 'Consumables' category.,SELECT * FROM items WHERE category = 'Consumables';," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
What is the total stock value for 'Consumables' items?,"SELECT SUM(s.quantity * i.unit_cost) AS total_value
FROM stock s JOIN items i ON s.item_id = i.item_id
WHERE i.category = 'Consumables';"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,join
Which warehouse has the highest total stock value?,"SELECT w.name, SUM(s.quantity * i.unit_cost) AS total_value
FROM stock s JOIN items i ON s.item_id = i.item_id
JOIN warehouses w ON s.warehouse_id = w.warehouse_id
GROUP BY w.name ORDER BY total_value DESC LIMIT 1;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,join
Find items that have never had any outbound shipment.,"SELECT i.name FROM items i
WHERE i.item_id NOT IN (
SELECT DISTINCT item_id FROM movements WHERE movement_type = 'shipment'
);"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,subquery
List the top 10 vendors by reliability score.,"SELECT name, reliability_score FROM vendors ORDER BY reliability_score DESC LIMIT 10;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
Find items where the on-hand quantity has not changed in the last 90 days.,"SELECT i.name, s.quantity, s.last_updated
FROM stock s JOIN items i ON s.item_id = i.item_id
WHERE s.last_updated < CURRENT_DATE - INTERVAL '90 days';"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,medium,select
Calculate inventory turnover per item (shipments / average stock).,"WITH shipped AS (
SELECT item_id, SUM(quantity) AS total_shipped
FROM movements WHERE movement_type = 'shipment'
GROUP BY item_id
),
avg_stock AS (
SELECT item_id, AVG(quantity) AS avg_qty FROM stock GROUP BY item_id
)
SELECT i.name, s.total_shipped, a.avg_qty,
ROUND(s.total_shipped::numeric / NULLIF(a.avg_qty, 0), 2) AS turnover_ratio
FROM items i
JOIN shipped s ON i.item_id = s.item_id
JOIN avg_stock a ON i.item_id = a.item_id
ORDER BY turnover_ratio DESC;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,cte
Find the vendor with the shortest average lead time.,"SELECT name, lead_time_days FROM vendors ORDER BY lead_time_days ASC LIMIT 1;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,easy,select
Show movements ranked by quantity within each warehouse.,"SELECT w.name AS warehouse, i.name AS item, m.quantity,
RANK() OVER (PARTITION BY m.warehouse_id ORDER BY m.quantity DESC) AS rank_in_warehouse
FROM movements m
JOIN warehouses w ON m.warehouse_id = w.warehouse_id
JOIN items i ON m.item_id = i.item_id;"," warehouses(warehouse_id, name, city, country, capacity)
items(item_id, name, sku, category, unit_cost, reorder_point)
stock(stock_id, item_id, warehouse_id, quantity, last_updated)
movements(movement_id, item_id, warehouse_id, movement_type, quantity, movement_date)
vendors(vendor_id, name, country, lead_time_days, reliability_score)",inventory,hard,window