Ancestry wants to understand which paid members had the most productive sessions in Ancestry Record Search during January 2025. Write a PostgreSQL query using a window function to return each paid member's best qualifying session, including paid members with no qualifying session.
Requirements
- Consider only members with a
Plus or Pro subscription.
- Include only completed sessions on the
Record Search surface from 2025-01-01 inclusive through 2025-02-01 exclusive.
- Rank each member's sessions by
result_count descending, then by started_at descending to break ties, and return rank 1 for each member.
- Preserve paid members without a qualifying session, showing
NULL session fields. Order the final results by member_id.