Skip to main content
Home/Challenges/Coding/SQL From Schema
IntermediateCoding~10 min

SQL From Schema

Write a prompt that produces a correct, optimised SQL query from a given schema — without any hallucinated column names.

Skills Tested

SQL generationSchema comprehensionQuery optimisation

Challenge Prompt

This is the example prompt structure. Write your own variation below.

Given this schema: users(id, email, created_at), orders(id, user_id, total_amount, status, created_at), order_items(id, order_id, product_id, quantity, unit_price). Write a SQL query that returns: the top 10 users by total spend in the last 30 days, showing user email, order count, and total spend, for users with at least 2 orders, ordered by total spend descending. Use PostgreSQL syntax, add an index hint comment.

Your Prompt

Write your own version. Every word matters — be specific.

🪙
Reward
+100 GeraCoins

Earn GeraCoins for completing this challenge. Redeem across all Gera products.

Hints (3)
  • 1Including the full schema in the prompt eliminates hallucinated column names.
  • 2"PostgreSQL syntax" avoids MySQL/generic SQL ambiguity.
  • 3Ask the AI to add a comment explaining the index that would help this query.

Related Topics

SQLPostgreSQLdatabase queryschemaquery optimisation
Browse All Challenges