{"id":"code-col-sql-above-course-average","audience":"college","category":"coding","track":"coding","technique":"context","title":"Find students above their course average, minus audit seats","free":false,"task":"For your TA dashboard project, list enrollments scoring above their own course's average. Audit enrollments (status 'audit') have no real score, so leave them out of both the averages and the results. Columns exactly student_name, course_code, score, ordered by course_code, then score highest first. Write one PostgreSQL query in exactly 1 code block of at most 18 lines, under 25 words of text.","materialLabel":"The schema (attached to your prompt automatically)","material":"-- PostgreSQL 16 - \"TA Helper\" class project, CS 3410 (team Ostrich)\n\nCREATE TABLE students (\n  id         SERIAL PRIMARY KEY,\n  full_name  TEXT NOT NULL\n);\n\nCREATE TABLE courses (\n  id    SERIAL PRIMARY KEY,\n  code  TEXT NOT NULL UNIQUE      -- e.g. 'CS 2110'\n);\n\nCREATE TABLE enrollments (\n  student_id  INT NOT NULL REFERENCES students(id),\n  course_id   INT NOT NULL REFERENCES courses(id),\n  status      TEXT NOT NULL,      -- 'credit' or 'audit'\n  score       NUMERIC(5,2),       -- audit rows store 0\n  PRIMARY KEY (student_id, course_id)\n);\n\n-- sample enrollments for CS 2110 (course_id 3)\n-- student | status | score\n-- 11      | credit | 91.00\n-- 12      | credit | 74.00\n-- 13      | audit  |  0.00\n-- 14      | credit | 83.00\n\n-- first attempt by Wren (returns students above the OVERALL average,\n-- not their course's):\n-- SELECT s.full_name, e.score FROM enrollments e\n-- JOIN students s ON s.id = e.student_id\n-- WHERE e.score > (SELECT AVG(score) FROM enrollments);","rules":[{"type":"codeBlocks","count":1},{"type":"maxCodeLines","max":18},{"type":"maxProseWords","max":25}],"mistakes":[{"title":"Using the overall average","why":"Wren's query compares everyone to one global average, which isn't what a TA needs.","fix":"Say: \"Above the average of their own course.\"","checks":["r0"]},{"title":"Counting audit seats","why":"Audit rows store 0, which drags each course average down unless you exclude them.","fix":"Add: \"Exclude status = 'audit' from the averages and the results.\"","checks":["r1"]},{"title":"Unnamed columns and no order","why":"The AI returns full_name and code with its own sort.","fix":"Add: \"Columns exactly student_name, course_code, score; ORDER BY course_code, score DESC.\"","checks":["r2"]},{"title":"Several versions and a walkthrough","why":"The AI shows a subquery version, a window version and explains both.","fix":"Add: \"One query in one code block, no alternatives.\"","checks":["codeBlocks","maxCodeLines","maxProseWords"]}],"promptHints":[{"label":"Says which average","patterns":["(own|their|same|each) course","per course","partition"]},{"label":"Handles audit rows","patterns":["audit"]},{"label":"Names the columns","patterns":["student_name","course_code"]},{"label":"Gives the order","patterns":["order by","highest first","desc"]},{"label":"Asks for one query","patterns":["one query","single query","one code block"]}],"hint":"'Above average' needs a definition: which average, and which rows count. Tell the AI both, plus the exact columns and order.","rubricLabels":["Compares each score with the average of the same course only (e.g. a correlated subquery on course_id or AVG(score) OVER (PARTITION BY course_id))","Excludes status = 'audit' rows from the averages and from the results (so CS 2110's average is 82.67, not 62)","Returns exactly the columns student_name, course_code and score, ordered by course_code and then score descending"]}