SELECT (sum(`result` = 1)/count(id) * 100) as `abc`,
case
when `abc` > 80 then 'pass'
when `abc` < 80 then 'fail'
end as `abcd`
FROM `user_quiz_answers` WHERE `user_quiz_id` = 39
表:
id int(11) AUTO_INCREMENT
question_id int(11)
result tinyint(1)
錯誤:
#1054 - Unknown column 'abc' in 'field list'
我已成功這一點,但不是上面的一個
SELECT
case
when (sum(`result` = 1)/count(id) * 100) > 80 then 'pass'
when (sum(`result` = 1)/count(id) * 100) < 80 then 'fail'
end as `abcd`
FROM `user_quiz_answers` WHERE `user_quiz_id` = 39
界定「不工作」 ...... –
@MitchWheat# 1054 - '字段列表'中未知列'abc' – aWebDeveloper
啊 - 你不能在你有的地方引用別名'abc' - 你需要再次複製那個SUM()語句。 – halfer