Return count and renewal percentage of unreturned good copies
MetaData Engineer · Technical ScreenLast updated
This question evaluates proficiency in SQL data manipulation, including conditional filtering, NULL handling, aggregation, and computing conditional percentages across related tables.
Tables: copies(copy_id, condition), checkouts(copy_id, checkout_date, return_date, renewal_count). Write a single SQL query that returns one row with two columns: (
- total_unreturned_good_copies: the count of active checkouts (return_date IS NULL) for copies whose condition = 'good' (exact match), and (
- pct_renewals_gt_2: among those active checkouts, the percentage with renewal_count > 2 (return a decimal fraction 0– 1).
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.