日期:2014-05-19  浏览次数:20272 次

分组查询
typecount       type   hotelno  
-----------   ----   -------
3                       B+       BA01
1                       A+       BA01
2                       A+       BA02
1                       S         BA02
现在想得到每个hotelno中不同type的count最多的那一种type
最后答案也就是
  type   hotelno  
  ----   -------  
  B+       BA01
  A+       BA02
怎么写?

------解决方案--------------------
select type,hotelno from 表 where typecount in (select top 1 typecount from 表 a where a.hotelno = 表.hotelno order by typecount)