获取5个最常用的值/出现的ID? [英] Get 5 most frequent values/occuring ids?

查看:56
本文介绍了获取5个最常用的值/出现的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取表格中出现次数最多的5个ID,我的表格如下所示:

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 |
+-----------+---------------------+---------+---------+

我当时正在考虑使用子查询来进行查询,而该查询是根据Deal_id的数量排序的?但是,如果有人可以提供帮助,则不能完全确定该怎么做,谢谢!

I was thinking of doing a query with a sub-query, something that orders by the count of deal_id? Not exactly sure how to go about it though, if anyone can help, thanks!

推荐答案

在(某种)通用SQL中:

In (sort of) generic SQL:

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

如果您要使用其他ID字段,只需将其替换为deal_id.

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

这篇关于获取5个最常用的值/出现的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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