我有一个“真实百分比值”,使用以下公式计算:
true% = true_answers/total_answers
其中total_answers是total_correct_answers和total_incorrect_answers的SUM。我使用以下查询来获取TRUE和FALSE答案。
SELECT
SUM(IF(true_answer = 1, 1, 0)) AS total_correct_answers,
SUM(IF(correct_answer != 1, 1, 0)) AS total_incorrect_answers FROM table
WHERE date BETWEEN '$from' AND '$to'
我使用PHP使用total_correct_answers和total_incorrect_answers计算total_answers和true_percentage值,并在jqgrid中显示这些值。现在我需要根据“true%”值对列表进行排序。怎么做到这一点?我试过了
ORDER BY SUM(IF(correct_answer = 1, 1, 0))/SUM(IF(correct_answer != 1,1,0))+SUM(IF(correct_answer = 1, 1, 0)) asc
但这是错误地排序网格。怎么办呢?