可以查看结构here
它是如何运作的是用户投票存储在'投票'表中并被'answer_id'列识别,我不知道如何统计它们并确定最高票数的答案
答案 0 :(得分:4)
怎么样
SELECT a.*, COUNT(v.id) tot
FROM answers a INNER JOIN votes v
on a.id = v.answer_id
GROUP BY a.id
ORDER BY tot DESC
如果您想在没有任何投票的情况下获得答案,请使用:
SELECT a.*, COUNT(v.id) tot
FROM answers a LEFT JOIN votes v
on a.id = v.answer_id
GROUP BY a.id
ORDER BY tot DESC