question
stringlengths
22
99
sql
stringlengths
34
502
schema_context
stringclasses
5 values
domain
stringclasses
5 values
difficulty
stringclasses
3 values
query_type
stringclasses
6 values
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(supplie...
ecommerce
easy
select
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(supplie...
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(supplie...
ecommerce
easy
select
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(supplie...
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(supplie...
ecommerce
easy
aggregate
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(supplie...
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(supplie...
ecommerce
easy
select
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(supplie...
ecommerce
easy
aggregate
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(supplie...
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(supplie...
ecommerce
easy
aggregate
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(supplie...
ecommerce
easy
aggregate
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(supplie...
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(supplie...
ecommerce
easy
aggregate
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(supplie...
ecommerce
easy
select
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(supplie...
ecommerce
easy
aggregate
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(supplie...
ecommerce
easy
aggregate
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(supplie...
ecommerce
easy
select
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(supplie...
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(supplie...
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(supplie...
ecommerce
easy
aggregate
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(supplie...
ecommerce
easy
select
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(supplie...
ecommerce
easy
aggregate
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(supplie...
ecommerce
easy
select
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(supplie...
ecommerce
easy
select
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(supplie...
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(supplie...
ecommerce
easy
aggregate
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(supplie...
ecommerce
easy
join
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(supplie...
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(supplie...
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(supplie...
ecommerce
easy
aggregate
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(supplie...
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(supplie...
ecommerce
easy
aggregate
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(supplie...
ecommerce
easy
select
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(supplie...
ecommerce
easy
aggregate
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(supplie...
ecommerce
easy
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(supplie...
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(supplie...
ecommerce
easy
aggregate
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(supplie...
ecommerce
easy
aggregate
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(supplie...
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(supplie...
ecommerce
easy
aggregate
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(supplie...
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(supplie...
ecommerce
easy
aggregate
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, ap...
healthcare
easy
select
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, ap...
healthcare
easy
aggregate
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, ap...
healthcare
easy
aggregate
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, ap...
healthcare
easy
aggregate
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, ap...
healthcare
easy
aggregate
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, ap...
healthcare
easy
select
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, ap...
healthcare
easy
aggregate
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, ap...
healthcare
easy
select
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, ap...
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, ap...
healthcare
easy
aggregate
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, ap...
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, ap...
healthcare
easy
aggregate
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, ap...
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, ap...
healthcare
easy
select
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, ap...
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, ap...
healthcare
easy
aggregate
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, ap...
healthcare
easy
select
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, ap...
healthcare
easy
aggregate
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, ap...
healthcare
easy
select
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, ap...
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, ap...
healthcare
easy
aggregate
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, ap...
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, ap...
healthcare
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, ap...
healthcare
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_...
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_...
analytics
easy
aggregate
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_...
analytics
easy
aggregate
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_...
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_...
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_...
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_...
analytics
easy
aggregate
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_...
analytics
easy
select
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_...
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_...
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_...
analytics
easy
aggregate
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_...
analytics
easy
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_...
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_...
analytics
easy
aggregate
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_...
analytics
easy
select
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_...
analytics
easy
aggregate
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_...
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_...
analytics
easy
select
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_...
analytics
easy
aggregate
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_...
analytics
easy
select
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(...
hr
easy
select
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(...
hr
easy
aggregate
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(...
hr
easy
join
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(...
hr
easy
select
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(...
hr
easy
join
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(...
hr
easy
aggregate
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(...
hr
easy
join
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(...
hr
easy
select
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(...
hr
easy
join
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(...
hr
easy
aggregate
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(...
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(...
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(...
hr
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...
inventory
easy
select