Library › Coding AI › Product managers
List Pro accounts with ticket counts, zeros included
Practice: Giving the right context. About 5 minutes.
About this exercise
Write one SQL query listing every account on the 'Pro' plan with its number of support tickets opened in Q3 2026 (July 1 to September 30), and accounts with zero tickets must still appear with 0. Columns: account name and ticket_count, highest count first. One code block, at most 12 lines, then under 25 words outside the code.
Common mistakes when you ask AI for this
- Not saying zeros matter. The AI writes an inner join, so quiet accounts silently disappear. Try: Add: "Accounts with zero tickets must appear with 0."
- Missing the WHERE trap. Even with a LEFT JOIN, a date filter in WHERE drops the zero-ticket accounts again. Try: Add: "Put the date filter in the ON clause, not WHERE."
- Counting rows, not tickets. COUNT(*) counts the empty joined row, so a quiet account shows 1. Try: Add: "Use COUNT(t.id), highest count first."
- Getting a menu of options. The AI likes to offer two or three versions of the query, so you're left to pick and test them yourself. Try: Add: "Give one query only, in one code block, no alternatives."
- Letting the code sprawl. The AI pads the query with extras nobody asked for, so it grows long and harder to check. Try: Add: "At most 12 lines of code."
- Getting a tutorial. By default the AI explains every part of the code at length, which you then have to scroll past. Try: Add: "After the code, one line under 15 words. Nothing else."
What a strong prompt includes
- Says zero-ticket accounts must show
- Places the date filter
- Sets the quarter
- Sets the sort
- Asks for one answer only
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)