我希望我的结果按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
答案 0 :(得分:2)
有点小错误。请尝试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
答案 1 :(得分:1)
您应该使用ORDER BY
来排序结果。 GROUP BY
用于汇总结果。
答案 2 :(得分:0)
尝试将其添加到最后:
ORDER BY
a.right DESC
答案 3 :(得分:0)
对于排序,您应该使用ORDER 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