PostgreSQL
因此,我想返回所有学生唯一的代码,这些代码通过了超过45%的测试而未通过。
答案 0 :(得分:0)
您可以使用此:
假定为数据- Grade (75 or above is passing) => grade < 75 is failed
SELECT code
FROM exams
GROUP BY code
HAVING SUM(CASE WHEN grade < 75 THEN 1 ELSE 0 END) :: FLOAT / COUNT(grade) > 0.45;
答案 1 :(得分:0)
我只是这样写:
SELECT e.code
FROM exams e
GROUP BY e.code
HAVING AVG( (e.grade < 75)::numeric ) > 0.45;