
A database outage blocked premium membership registrations from 2025-01-01 to 2025-03-31 (inclusive). Members intend to start on intended_start_date, are billed monthly in arrears at $10/month only after their registration is recorded (registered_date). Some users registered after the outage; some are still missing. For each affected user, the lost revenue equals $10 for each calendar month within the outage window during which the user was not yet registered by that month’s end. Write a single PostgreSQL query that returns: (1) total dollars lost, and (2) a breakdown of users by months_lost ∈ {1,2,3} with counts. Rules: use the earliest registered_date per user; count months precisely using calendar boundaries; include users with NULL registered_date; ignore users whose intended_start_date is after 2025-03-31; deduplicate inputs. Use the following schema and sample ASCII tables:
Tables:
Sample data: premium_intended_enrollments +---------+---------------------+ | user_id | intended_start_date | +---------+---------------------+ | U2 | 2025-01-05 | | U3 | 2025-01-20 | | U4 | 2025-02-03 | | U5 | 2025-03-25 | | U6 | 2025-03-30 | | U8 | 2025-01-10 | | U9 | 2025-02-20 | | U10 | 2025-03-15 | +---------+---------------------+
premium_actual_registrations +---------+-----------------+ | user_id | registered_date | +---------+-----------------+ | U2 | 2025-04-05 | | U3 | 2025-03-10 | | U4 | 2025-04-02 | | U5 | 2025-04-02 | | U6 | 2025-06-01 | | U8 | NULL | | U9 | NULL | | U10 | NULL | +---------+-----------------+
outage_window +------------+------------+ | start_date | end_date | +------------+------------+ | 2025-01-01 | 2025-03-31 | +------------+------------+
Output requirements: