我希望我的结果按a.right
排序(它可能有2个值:1-true,0-false)。 a.right=1
必须排在第一行。尝试GROUP BY
。但是没有帮助。如何达到以上效果?
SELECT
u.fullname,
a.id,
a.content,
a.addDT,
a.`right`,
acr.score,
acr.checkDT
FROM
answers a
INNER JOIN users u ON u.id = a.uid
LEFT JOIN `answer_chk_results` acr ON acr.aid = a.id
WHERE
a.qid = 1
GROUP BY
a.`right` DESC
最佳答案
有点错误。尝试使用ORDER BY
代替GROUP BY
。 ORDER BY
用于对记录进行排序,而GROUP BY
用于聚合记录。
您的查询应为
SELECT
u.fullname,
a.id,
a.content,
a.addDT,
a.`right`,
acr.score,
acr.checkDT
FROM
answers a
INNER JOIN users u ON u.id = a.uid
LEFT JOIN `answer_chk_results` acr ON acr.aid = a.id
WHERE
a.qid = 1
ORDER BY
a.`right` DESC