2009-04-15 79 views
1

一起算我在Oracle数据库下表(简体):Max在SQL查询

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

我要选择具有此表中的最高appearence的modeldescription。问题是可以有几乎无限的模型描述。 所以结果集看起来应该是这样的:

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

按照最高的外观你的意思是最高的按照productId排序? – 2009-04-15 11:04:39

回答

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

泰兹这就是我正在寻找 – Red33mer 2009-04-15 11:42:09

1

此外,如果只想最高添加以下内容:

选择前1 modeldescription ......