对前十个查询进行排序
感谢您的阅读。
我正在尝试编写一个查询来列出使用两个表获得最多选票的人的姓名:
-------
votes
-------
vote_id, giver_user_id, receiver_user_id, datetime
等等...
-------
users
-------
user_id, name, surname
等等...
到目前为止我已经:
$top_query = "SELECT * FROM vote, user WHERE vote.receiver_user_id = user.user_id GROUP BY receiver_user_id ";
这种工作,但它没有列出用户得票最多的人位于列表顶部。
我怎样才能这样订购呢?
谢谢。
OP
Thanks for reading.
I'm trying to write a query to list the names of people who have recevied the most votes using two tables:
-------
votes
-------
vote_id, giver_user_id, receiver_user_id, datetime
etc..
-------
users
-------
user_id, name, surname
etc...
So far I have:
$top_query = "SELECT * FROM vote, user WHERE vote.receiver_user_id = user.user_id GROUP BY receiver_user_id ";
This kind of works, but it doesn't list the user with the most votes at the top of the list.
How can I order it this way?
Thank you.
OP
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 ORDER BY 子句。
使用关键字“asc”或“desc”
类似:
Mysql参考:
http://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html
You can use the ORDER BY clause.
With the keyword "asc" or "desc"
Something like :
Mysql reference :
http://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html
这将按接收者分组并按投票降序排列:
This will group by receiver and order by votes in descending order: