开发者

Get 5 most frequent values/occuring ids?

I'm trying to get the 5 most occurring IDs in my table, my table looks like this:

+-----------+---------------------+---------+---------+
| mashup_id | mashup_time         | user_id | deal_id |
+-----------+---------------------+---------+---------+
|         1 | 2011-08-24 21:58:22 |       1 |   23870 |
+-----------+---------------------+---------+---------+

I was thinking of doing a query with a sub-query, someth开发者_Go百科ing that orders by the count of deal_id? Not exactly sure how to go about it though, if anyone can help, thanks!


In (sort of) generic SQL:

SELECT deal_id, COUNT(*)
  FROM your_table
 GROUP BY deal_id
 ORDER BY COUNT(*) DESC
 LIMIT 5

If you meant a different ID field, just substitute it for deal_id.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜