一个SQL查询中的最大计数 [英] max count together in an sql query

查看:166
本文介绍了一个SQL查询中的最大计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在oracle数据库中有下表(简体):

I have the following table (simplified) in an oracle db:

productId  |  modelDescription 
         1 |             thing
         2 |     another thing
         3 |       not a thing
         4 |             thing

我想选择此表中出现频率最高的模型描述.问题在于可能存在几乎无限的模型描述. 因此结果集应如下所示:

I want to select the modeldescription which has the highest appearence in this table. The problem is that there can be nearly infinite model descriptions. So the resultset should look like something like this:

modelDescription | appearance 
           thing |          2 
   another thing |          1 
             ... |        ...

推荐答案

select modeldescription, count(modeldescription) 
from products 
group by modeldescription
order by 2 desc

这篇关于一个SQL查询中的最大计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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