Recap - Creatures
Part of the Fundamentals section of Coddy's SQL journey — lesson 70 of 72.
Challenge
MediumAvailable tables and columns:
<strong>creatures</strong>:<strong>creature_name</strong>,<strong>preference</strong>,<strong>has_legs</strong>
In this challenge, we have creatures that want to find a significant other. We need to help them find their match.
Each creature has a preference value and either has legs or doesn't have legs.
Rules:
- Creatures are matched ONLY with others sharing the same
has_legsvalue - Within each group (
has_legstrue/false), order creatures by preference - Assign
couple_matchernumbers usingNTILE(total_creature_count/2) - Both groups are numbered starting from 1 (a smaller group simply fills fewer buckets)
Example: 10 total creatures (6 with legs, 4 without)
- Creatures with legs: ranked by preference, assigned
couple_matcher1-5 - Creatures without legs: ranked by preference, assigned
couple_matcher1-5 - Result: Multiple separate couples can have the same
couple_matchernumber
Try it yourself
All lessons in Fundamentals
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns