Library › Coding AI › Nonprofit staff
Find lapsed donors for a win-back appeal
Practice: Giving the right context. About 5 minutes.
About this exercise
Write one SQL query listing donors who gave in fiscal year 2026 (2025-07-01 up to 2026-07-01) but haven't given anything since 2026-07-01. Use NOT EXISTS for the second part. Leave out donors with do_not_contact = true. Return columns named exactly donor_id, name and last_gift_on, most recent last gift first. One code block, at most 16 lines, then under 25 words outside the code.
Common mistakes when you ask AI for this
- Not giving the fiscal year. The AI uses calendar 2026 or the last 12 months. Try: Add: "FY2026 = 2025-07-01 up to 2026-07-01."
- Leaving "lapsed" vague. The AI forgets to check for newer gifts, or uses NOT IN, which breaks with NULLs. Try: Add: "NOT EXISTS any gift on or after 2026-07-01. Skip do_not_contact."
- Leaving the output open. The AI picks its own column names and order. Try: Add: "Columns donor_id, name, last_gift_on, most recent 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."
- 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 12 words. Nothing else."
What a strong prompt includes
- Gives the fiscal year
- Defines lapsed
- Respects do-not-contact
- Sets the output
- 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)