{"id":"code-dev-explain-query-to-analyst","audience":"developers","category":"coding","track":"coding","technique":"audience","title":"Explain a SQL query to an analyst in 4 labeled lines","free":false,"task":"Analyst Rosa asks why the weekly report is missing some users. Explain the query in exactly 4 numbered lines labeled 'Rows:', 'Filter:', 'Groups:' and 'Watch out:', each under 25 words. 'Watch out:' must say that the INNER JOIN drops users with no sessions that week. Rosa knows SQL basics, so no tutorials, and don't rewrite the query. No code blocks, under 100 words.","materialLabel":"The query and Rosa's message (attached to your prompt automatically)","material":"-- reports/weekly_active.sql  (PostgreSQL 16, Driftwood analytics)\nSELECT\n  u.plan,\n  COUNT(DISTINCT u.id)            AS users,\n  ROUND(AVG(s.duration_sec) / 60) AS avg_minutes\nFROM users u\nJOIN sessions s\n  ON s.user_id = u.id\n AND s.started_at >= date_trunc('week', now()) - interval '1 week'\n AND s.started_at <  date_trunc('week', now())\nWHERE u.deleted_at IS NULL\n  AND u.plan <> 'internal'\nGROUP BY u.plan\nORDER BY users DESC;\n\n-- Rosa (#analytics, Thursday):\n-- \"Hi! The 'users' column in the weekly report adds up to 8,412 but\n--  the admin page says we have 9,960 non-deleted customers. Is the\n--  query dropping people? I'm comparing it to my own export for the\n--  board deck on Monday.\"\n--\n-- Notes:\n-- - 'internal' plan = our own staff accounts\n-- - date_trunc('week', ...) starts weeks on Monday\n-- - avg_minutes is per session, not per user","rules":[{"type":"numberedItems","count":4},{"type":"codeBlocks","count":0},{"type":"maxProseWords","max":100}],"mistakes":[{"title":"A line-by-line tutorial","why":"The AI explains SELECT, JOIN and GROUP BY from scratch, which Rosa doesn't need.","fix":"Say: \"Rosa knows SQL basics. Exactly 4 labeled lines.\"","checks":["numberedItems","maxProseWords"]},{"title":"No fixed labels","why":"Without labels the explanation wanders and the key point gets buried.","fix":"Give them: \"Rows:, Filter:, Groups:, Watch out:\".","checks":["r0"]},{"title":"Burying the answer","why":"Rosa's real question is the missing users; the AI may mention the join only in passing.","fix":"Add: \"Watch out: the INNER JOIN drops users with no sessions that week.\"","checks":["r2","r1"]},{"title":"A rewritten query","why":"The AI 'fixes' the query with a LEFT JOIN, which changes what the report means.","fix":"Add: \"Don't rewrite the query. No code blocks.\"","checks":["codeBlocks","r2"]}],"promptHints":[{"label":"Says who it's for","patterns":["rosa","analyst","knows sql"]},{"label":"Gives the labels","patterns":["rows:","filter:","groups:","watch out"]},{"label":"Names the missing-users cause","patterns":["inner join","no sessions","drops"]},{"label":"Rules out a rewrite","patterns":["don'?t rewrite","no code","not rewrite"]},{"label":"Caps each line","patterns":["\\d+\\s*words"]}],"hint":"Rosa has one question and knows the basics. Give the AI her level, the labels you want and the one thing she must not miss.","rubricLabels":["The 4 numbered lines start with the labels Rows:, Filter:, Groups: and Watch out:, in that order","Filter: mentions that deleted users and the internal plan are excluded and that only last week's sessions (Monday to Monday) count","Watch out: says the INNER JOIN drops users who had no sessions last week, and the query is not rewritten anywhere"]}