我有问题,请查看我的数据库:
------------------- | id | article_id | ------------------- | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 2 | | 5 | 2 | | 6 | 3 | | 7 | 3 | | 8 | 3 | | 9 | 3 | | 10 | 3 |
我想收到这样的信息(按投票顺序,从最高到最低):
--------------------------- | id | article_id | votes | --------------------------- | 1 | 3 | 5 | | 2 | 1 | 3 | | 3 | 2 | 2 |
您能帮我写正确的SQL查询吗?
SELECT article_id, COUNT(article_id) AS votes FROM votes_table GROUP BY article_id ORDER BY votes DESC;