简体   繁体   English

在SQL查询中最大计数

[英]max count together in an sql query

I have the following table (simplified) in an oracle db: 我在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

In addition, if you only want the highest add the following: 此外,如果您只想要最高添加以下内容:

Select Top 1 modeldescription...... 选择Top 1 modeldescription ......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM