当前位置: 代码迷 >> Sql Server >> 分组查询,该如何解决
  详细解决方案

分组查询,该如何解决

热度:0   发布时间:2016-04-27 20:18:35.0
分组查询
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)
  相关解决方案