Compute reservation diff for largest member
MetaData Engineer · Technical ScreenLast updated
This question evaluates competency in relational data manipulation and aggregation using SQL or Python, including joins, grouping, and handling missing referrer relationships.
Given copies(copy_id, reserved_by_member_id) and members(member_id, referred_by_member_id), find the member with the largest member_id. Return a single row with: member_id, referred_by_member_id, and diff_of_reserved_copy_num defined as (number of copies reserved by that member) minus (number of copies reserved by their referrer). If the referrer is NULL or has no reservations, treat their count as 0.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.