SQL challenges

Practice problem statements with input format, output format, constraints and solutions.

beginner

SQL Introduction challenge

Build a small solution that uses SQL Introduction in SQL and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

SELECT customer, total, status
FROM orders
WHERE total >= 50
ORDER BY total DESC;

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core sql introduction pattern before polishing the final output.

Solution

SELECT customer, total, status
FROM orders
WHERE total >= 50
ORDER BY total DESC;
beginner

SELECT challenge

Build a small solution that uses SELECT in SQL and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

SELECT customer, total, status
FROM orders
WHERE total >= 51
ORDER BY total DESC;

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core select pattern before polishing the final output.

Solution

SELECT customer, total, status
FROM orders
WHERE total >= 51
ORDER BY total DESC;
beginner

WHERE challenge

Build a small solution that uses WHERE in SQL and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

SELECT customer, total, status
FROM orders
WHERE total >= 52
ORDER BY total DESC;

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core where pattern before polishing the final output.

Solution

SELECT customer, total, status
FROM orders
WHERE total >= 52
ORDER BY total DESC;
beginner

ORDER BY challenge

Build a small solution that uses ORDER BY in SQL and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

SELECT customer, total, status
FROM orders
WHERE total >= 53
ORDER BY total DESC;

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core order by pattern before polishing the final output.

Solution

SELECT customer, total, status
FROM orders
WHERE total >= 53
ORDER BY total DESC;
beginner

LIMIT challenge

Build a small solution that uses LIMIT in SQL and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

SELECT customer, total, status
FROM orders
WHERE total >= 54
ORDER BY total DESC;

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core limit pattern before polishing the final output.

Solution

SELECT customer, total, status
FROM orders
WHERE total >= 54
ORDER BY total DESC;
beginner

INSERT challenge

Build a small solution that uses INSERT in SQL and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

INSERT INTO orders (customer, total, status)
VALUES ('Asha', 55, 'paid');

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core insert pattern before polishing the final output.

Solution

INSERT INTO orders (customer, total, status)
VALUES ('Asha', 55, 'paid');
beginner

UPDATE challenge

Build a small solution that uses UPDATE in SQL and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

UPDATE orders
SET status = 'refunded'
WHERE id = 42 AND status = 'paid';

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core update pattern before polishing the final output.

Solution

UPDATE orders
SET status = 'refunded'
WHERE id = 42 AND status = 'paid';
beginner

DELETE challenge

Build a small solution that uses DELETE in SQL and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

SELECT customer, total, status
FROM orders
WHERE total >= 57
ORDER BY total DESC;

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core delete pattern before polishing the final output.

Solution

SELECT customer, total, status
FROM orders
WHERE total >= 57
ORDER BY total DESC;
beginner

GROUP BY challenge

Build a small solution that uses GROUP BY in SQL and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

SELECT status, COUNT(*) AS orders, SUM(total) AS revenue
FROM orders
GROUP BY status
HAVING SUM(total) >= 58;

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core group by pattern before polishing the final output.

Solution

SELECT status, COUNT(*) AS orders, SUM(total) AS revenue
FROM orders
GROUP BY status
HAVING SUM(total) >= 58;
beginner

HAVING challenge

Build a small solution that uses HAVING in SQL and handles one normal case plus one edge case.

Input format

Use a short text value, array, query, or sample object depending on the topic.

Output format

Print, render, or return the processed result in a readable format.

Constraints

  • Keep the solution under 60 lines.
  • Use descriptive names.
  • Do not depend on hidden external services.

Starter code

SELECT status, COUNT(*) AS orders, SUM(total) AS revenue
FROM orders
GROUP BY status
HAVING SUM(total) >= 59;

Test cases

  • basic sample - valid processed result
  • empty or small sample - safe fallback result

Hint

Focus on the core having pattern before polishing the final output.

Solution

SELECT status, COUNT(*) AS orders, SUM(total) AS revenue
FROM orders
GROUP BY status
HAVING SUM(total) >= 59;