Members Who Switched From Brand to Generic Within Ninety Days
Last updated: November 29, 2026
Quick Overview
Using claims (member_id, fill_date, gpi, is_brand) where gpi identifies the clinical drug, find members who filled a brand version of a drug and then filled the generic version of the same gpi within 90 days, and report the switch rate per gpi.
CVS Health
November 29, 20260
0
0 solved
Using claims (member_id, fill_date, gpi, is_brand) where gpi identifies the clinical drug, find members who filled a brand version of a drug and then filled the generic version of the same gpi within 90 days, and report the switch rate per gpi.
CVS Caremark, the pharmacy benefit manager, tracks generic dispensing and brand to generic conversion because it drives plan cost. The interviewer checks self-join logic with time bounds and a sound denominator.
What the Interviewer Expects
- Self-joins on member and drug identifier with a time window
- Requires the generic fill to come after the brand fill
- Counts distinct members to avoid double counting multiple fills
- Defines the switch rate denominator clearly
- Considers members whose 90 day window is not complete
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you find members who switched back to brand afterward?
- How would you write this with window functions instead of a self-join?
- How would you adjust for generics that launched mid-year?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
claims(member_id, fill_date, gpi, is_brand). GPI groups the same molecule, strength and form across manufacturers. A switcher has a brand fill on date d and a generic fill on the same gpi in (d, d +...
Approach
Take each member's first brand fill per gpi. Use EXISTS to check for a generic fill in the window, which avoids duplicate rows from multiple generic fills. Restrict to members with a complete window, ...