首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

分组查询,该如何解决

2012-02-21 
分组查询typecounttypehotelno----------------------3B+BA011A+BA012A+BA021SBA02现在想得到每个hotelno

分组查询
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)

热点排行
Bad Request.