Library › Data AI › Business analysts
Write SQL for customers with two or more active subscriptions
- For Business analysts
- You practice Setting limits and rules
- Time about 5 minutes
- Level Beginner
About this exercise
Customer success wants to know who holds two or more active subscriptions. Ask for one Postgres query in a single code block with at most 25 words outside it. Count only subscriptions with status 'active', leave out test customers, and sort by the count highest first, then by name.
Common mistakes when you ask AI for this
- Counting every subscription. The AI counts paused and cancelled plans too. Try: Add: "Count only status = 'active'."
- Filtering the count in WHERE. The AI puts the count test in WHERE, which errors. Try: Add: "GROUP BY customer, then HAVING COUNT(*) >= 2."
- Missing columns or order. The AI returns extra columns in no particular order. Try: Add: "Columns customer_id, name, active_subs; ORDER BY active_subs DESC, name."
- Leaving the format to chance. The AI picks its own length and layout unless told the exact shape. Try: Add: "Put the code in exactly 1 code block. Keep the writing outside the code under 25 words."
What a strong prompt includes
- Says active only
- Says HAVING
- Excludes test customers
- Names the columns and sort
- Caps the writing
Related exercises
- Accept the buyer's counteroffer on three stated conditions (Sales AI · Sales and customer success)
- Accrue goods received but not invoiced at PO price (Finance AI · Accountants)
- Acknowledge a cancellation request without a save attempt (Customer Support & Success AI · Customer success managers)
- Acknowledge an accessibility bug without a promised date (Customer Support & Success AI · Customer support teams)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)