{"id":"code-work-cs-sql-reopen-rate-by-agent","audience":"customer-support","category":"coding","track":"coding","technique":"context","title":"Rank agents by reopen rate without small samples","free":false,"task":"Write one SQL query for tickets solved in October 2026 that gives each agent's reopen rate: a solved ticket counts as reopened if it has a reopened event within 7 days after solved_at. Leave out agents with fewer than 20 solved tickets in October, since small samples mislead. Return columns named exactly agent, solved, reopened and reopen_pct (rounded to 1 decimal, no integer division), highest reopen_pct first. One code block, at most 24 lines, then under 25 words outside the code.","materialLabel":"Schema and sample rows (attached to your prompt automatically)","material":"HELPDESK DATABASE - Copper Kettle support (Postgres)\n\ntickets: id, assignee, solved_at (timestamp, NULL if open)\nticket_events: ticket_id, event ('reopened', 'note', 'tag_added', ...), at (timestamp)\n\nSample tickets:\n4401 | rosa | 2026-10-03 10:00\n4402 | sam | 2026-10-03 11:30\n4410 | deb | 2026-10-30 16:00\n4415 | lina (temp) | 2026-10-21 09:00\n\nSample events:\n4401 | reopened | 2026-10-05 08:00\n4401 | reopened | 2026-10-06 12:00\n4402 | reopened | 2026-10-25 09:00\n4410 | reopened | 2026-11-02 10:00\n\nNotes from Rosa:\n- Lina covered for one week and solved 6 tickets.\n- Some tickets bounce back more than once.\n- Customers can reopen a ticket for 30 days.\n- The October team meeting reviews these numbers.","rules":[{"type":"codeBlocks","count":1},{"type":"maxCodeLines","max":24},{"type":"maxProseWords","max":25}],"mistakes":[{"title":"Leaving \"reopened\" vague","why":"The AI counts every reopen event, so a ticket that bounced twice counts twice.","fix":"Add: \"A ticket counts once if reopened within 7 days after solved_at.\"","checks":["r0"]},{"title":"Forgetting small samples","why":"A temp with 6 tickets and 2 reopens tops the list.","fix":"Add: \"Leave out agents with fewer than 20 solved.\"","checks":["r1"]},{"title":"Leaving the output open","why":"The AI picks its own names, sort and math, sometimes dividing integers to 0.","fix":"Add: \"Columns agent, solved, reopened, reopen_pct (100.0, 1 decimal), highest first.\"","checks":["r2"]},{"title":"Getting a menu of options","why":"The AI likes to offer two or three versions of the query, so you're left to pick and test them yourself.","fix":"Add: \"Give one query only, in one code block, no alternatives.\"","checks":["codeBlocks","maxCodeLines"]},{"title":"Getting a tutorial","why":"By default the AI explains every part of the code at length, which you then have to scroll past.","fix":"Add: \"After the code, one line under 12 words. Nothing else.\"","checks":["maxProseWords"]}],"promptHints":[{"label":"Defines reopened","patterns":["7 days","within","once"]},{"label":"Sets a minimum sample","patterns":["20","having","small sample|minimum"]},{"label":"Sets the month","patterns":["october","2026-10"]},{"label":"Sets the output","patterns":["reopen_pct","100\\.0","desc|highest"]},{"label":"Asks for one answer only","patterns":["\\b(one|single|1)\\s+(query|code block|block|version)","only one","no (alternatives|options|other versions)"]}],"hint":"Look at ticket 4401 and at Lina's week. Tell the AI how to count each ticket and who's too small a sample to rank.","rubricLabels":["Keeps tickets with solved_at >= '2026-10-01' and < '2026-11-01' and counts a ticket as reopened only if it has a 'reopened' event after solved_at and within 7 days of it, counting each ticket once even with several reopens","Drops agents with fewer than 20 solved tickets (HAVING COUNT(*) >= 20)","Returns columns named exactly agent, solved, reopened and reopen_pct, with reopen_pct using 100.0 (or a numeric cast) rounded to 1 decimal, ordered by reopen_pct descending"]}