Purchase Frequency in an Audio App

Purchase Frequency in an Audio App

You analyze monetization for an audiobook app. The subscription team wants to compare every listener by the number of completed purchases in Q2 2026, including people who bought nothing. Each purchase record counts separately, even when the same listener made two purchases at the exact same second. Return columns: - listener_id — listener identifier, integer - listener_name — listener name - purchase_frequency — number of completed purchases from 2026-04-01 inclusive to 2026-07-01 exclusive, integer Rules: - Return every listener from listeners, including those with frequency 0. - Count only rows with status completed and a non-NULL completed_at inside the specified half-open interval. - Different purchase_id values are separate purchases; identical timestamps are not duplicates. - Sort by purchase_frequency descending, then listener_id ascending. - No rounding is needed; purchase_frequency must not be NULL.

Expected output sample

This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables. Your answer must use the same column names as this sample — alias them with AS if needed.

listener_idlistener_namepurchase_frequency
1Avery Stone3
4Devon Lake3
3Casey Moon2
PostgreSQLv16

Your query result will appear here

Focus radio
Paused · SomaFM · Fluid