Menu
Coddy logo textTech

Recap - Creatures

Part of the Fundamentals section of Coddy's SQL journey — lesson 70 of 72.

challenge icon

Challenge

Medium

Available 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_legs value
  • Within each group (has_legs true/false), order creatures by preference
  • Assign couple_matcher numbers using NTILE(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_matcher 1-5
  • Creatures without legs: ranked by preference, assigned couple_matcher 1-5
  • Result: Multiple separate couples can have the same couple_matcher number

Try it yourself

All lessons in Fundamentals