Mysql - 查询的排名字段
如何在查询结果集中添加包含行排名的字段?
最初我使用 php 对结果进行排名,因为它都在一个页面上。现在我已经添加了多个页面,所以现在即使我在第二页上,页面上的第一个结果仍然是“第一”。显然,我可以将页码乘以每页的结果数,然后添加结果数,但我想查询中有更好的方法。
谢谢,
How can I add a field that contains a rows rank within the result set of a query?
Initially I used php to rank my results as it was all on a single page. Now I have added multiple pages so now even though I am on the second page the first result on the page is still '1st'. Obviously I could multiply the page number by the number of results per page and add the result number but I imagine there is a better way within the query.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种方法。
使用 GROUP_CONCAT。只要设置不是太大,这个方法就很好用。请参阅: http://rpbouman.blogspot.com/2009/ 09/mysql-another-ranking-trick.html
使用自连接。请参阅我提供的第一个链接。不过可能会很慢。
There are couple of ways.
use GROUP_CONCAT. this works nice as long as the sett isn't too large. See: http://rpbouman.blogspot.com/2009/09/mysql-another-ranking-trick.html
with self join. see the first link i provided. might be slow though.