~[tlist_sql;
WITH samplescore AS (
SELECT
studenttestscore.testscoreid,
MAX(studenttestscore.numscore) as num,
MAX(studenttestscore.percentscore) as pct,
MAX(studenttestscore.alphascore) as alpha
FROM
studenttestscore INNER JOIN
studenttest ON studenttestscore.studenttestid = studenttest.id
WHERE
studenttest.testid = ~(gpv.testid)
GROUP BY
studenttestscore.testscoreid
)
SELECT
testscore.name,
testscore.id,
samplescore.num,
samplescore.pct,
samplescore.alpha
FROM
testscore INNER JOIN
samplescore ON testscore.id = samplescore.testscoreid
WHERE
testid = ~(gpv.testid)
ORDER BY
sortorder
]