SQL practice questions
Browse 20 practice questions and their starter queries. Query execution, submissions and progress tracking are currently unavailable.
Read each problem, identify the columns and tables you need, then work through the starter query. For guided learning, explore the Data Analyst SQL curriculum and portfolio projects.
All students
Easy
Return every row from the students table.
Starter SQL
SELECT * FROM students;High scorers
Easy
Find score rows where score is at least 90.
Starter SQL
SELECT * FROM scores
WHERE score >= 90;Top scores first
Easy
Return all scores ordered from highest to lowest.
Starter SQL
SELECT * FROM scores
ORDER BY score DESC;Students in Delhi
Easy
Return students who live in Delhi.
Starter SQL
SELECT * FROM students
WHERE city = 'Delhi';Uppercase student names
Easy
Return each student name in uppercase using a string function.
Starter SQL
SELECT UPPER(name) AS name_upper
FROM students;Student course titles
Medium
List each student name with module and score by joining students to scores.
Starter SQL
SELECT s.name, sc.module, sc.score
FROM students s
JOIN scores sc ON sc.student_id = s.id;Average score by module
Medium
For each module, return the average score.
Starter SQL
SELECT module, AVG(score) AS avg_score
FROM scores
GROUP BY module;Modules with high averages
Medium
Return modules whose average score is above 85.
Starter SQL
SELECT module, AVG(score) AS avg_score
FROM scores
GROUP BY module
HAVING AVG(score) > 85;Above class average
Hard
Return students whose score is above the overall average (use a subquery).
Starter SQL
SELECT s.name, sc.score
FROM students s
JOIN scores sc ON sc.student_id = s.id
WHERE sc.score > (
SELECT AVG(score) FROM scores
);Pass or fail label
Medium
Label each score as Pass (>= 60) or Fail using CASE.
Starter SQL
SELECT student_id, score,
CASE WHEN score >= 60 THEN 'Pass' ELSE 'Fail' END AS result
FROM scores;Rank scores
Hard
Rank scores within each module using a window function.
Starter SQL
SELECT module, student_id, score,
RANK() OVER (PARTITION BY module ORDER BY score DESC) AS rank_in_module
FROM scores;Top scorer per module
Hard
Use a CTE to list the highest score in each module.
Starter SQL
WITH max_scores AS (
SELECT module, MAX(score) AS top_score
FROM scores
GROUP BY module
)
SELECT * FROM max_scores;Customers in Jaipur
Easy
Return customers who live in Jaipur.
Starter SQL
SELECT * FROM customers
WHERE city = 'Jaipur';Product catalog
Easy
List product name and price for every product.
Starter SQL
SELECT name, price FROM products;Order lines
Medium
Show customer name, product name, quantity, and order_date for each order.
Starter SQL
SELECT c.name AS customer, p.name AS product, o.quantity, o.order_date
FROM orders o
JOIN customers c ON c.id = o.customer_id
JOIN products p ON p.id = o.product_id;Products starting with N
Easy
Find products whose name starts with the letter N.
Starter SQL
SELECT name, price
FROM products
WHERE name LIKE 'N%';All patients
Easy
Return every row from the patients table.
Starter SQL
SELECT * FROM patients;Patients in Toronto
Easy
List patients who live in Toronto.
Starter SQL
SELECT * FROM patients
WHERE city = 'Toronto';Patient admissions
Medium
Show each patient's first name, last name, admission date, and diagnosis.
Starter SQL
SELECT p.first_name, p.last_name, a.admission_date, a.diagnosis
FROM patients p
JOIN admissions a ON a.patient_id = p.patient_id;Admissions per doctor
Medium
Count admissions handled by each doctor (show doctor_id and total).
Starter SQL
SELECT attending_doctor_id, COUNT(*) AS admission_count
FROM admissions
GROUP BY attending_doctor_id;