American Airlines wants to run a randomized experiment using eligible AAdvantage passengers from recent flight bookings. Write a PostgreSQL query that assigns each eligible passenger ID to one of three mutually exclusive groups: 10% treatment, 10% holdout, and 80% control.
Requirements
- Include only passengers with a confirmed booking between 2026-07-01 and 2026-07-31.
- Remove duplicate passengers who have multiple qualifying bookings.
- Randomize the eligible passengers, then assign the first 10% to
treatment_10_pct, the next 10% to holdout_10_pct, and the remainder to control_80_pct.
- Return each passenger ID, assigned group, and position within that group. For sample data with 10 eligible passengers, the groups should contain 1, 1, and 8 passengers.
Output details
- Return columns in this order:
passenger_id, group_name, position_in_group.
- Order results by groups as
treatment_10_pct, holdout_10_pct, then control_80_pct, with positions ascending within each group.
- Order passengers deterministically by ascending
md5(passenger_id::text).
- Use ceiling thresholds: treatment through
CEIL(eligible_count * 0.10) and holdout through CEIL(eligible_count * 0.20).
- Interpret the date range as inclusive of
2026-07-01 and exclusive of 2026-08-01.