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
More Coding challenges
View all Coding →Intermediate
Armenian Phone Validator
Generate a regex that correctly validates Armenian mobile phone numbers — covering all network prefixes and the +374 country code.
AdvancedFind the Bug
Write a prompt that makes the AI identify ALL bugs in a given broken Python function — without fixing them first.
AdvancedTypeScript Interface Architect
Write a TypeScript interface for a complex nested API response — handling optional fields, union types, and ISO dates correctly.