简体   繁体   中英

max count together in an sql query

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

In addition, if you only want the highest add the following:

Select Top 1 modeldescription......

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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