MySQL - 生成最“流行"记录的列表 [英] MySQL - generate a list of most 'popular' records

查看:22
本文介绍了MySQL - 生成最“流行"记录的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码生成某个 release_id 在表中出现的次数的列表

I am using the following code to generate a list of how many times a certain release_id appears in a table

所以 release_id 可以在我的表中出现多次.

So release_id can appear multiple times in my table.

SELECT release_id, COUNT( release_id ) 
FROM charts_extended
GROUP BY release_id
ORDER BY COUNT( release_id ) DESC 
LIMIT 0 , 30

示例输出

release_id COUNT(release_id)
1231287 76
177617 73
12218 67

例如1231287在表格中出现了76次

e.g. 1231287 appears 76 times in the table

我现在如何输出 release_id 出现的排名数字

How can I now output what number in rank the release_id appears

例如

1231287 = #112218 = #3

1231287 = #1 12218 = #3

'release_id 1231287 是最受欢迎的'12218 是第二受欢迎的'

'release_id 1231287 is the most popular '12218 is the 2nd most popular'

推荐答案

使用 rownum 模拟.看到这个链接,看起来是一篇不错的文章.http://craftycodeblog.com/2010/09/13/rownum-simulation-with-mysql/

Use a rownum simulation. See this link, it looks like a good article. http://craftycodeblog.com/2010/09/13/rownum-simulation-with-mysql/

或者这个.

MySQL 通过选择 rownum 作为起始值来限制选择

这篇关于MySQL - 生成最“流行"记录的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆