在线等,得到表TopSales里每个类别CategoryID的前2条数据的集合
比如
TopSales:
CategoryID RefKey
300001 101
300001 102
300001 103
300002 104
300002 105
300002 106
300003 107
300003 108
300003 109
300003 110
300003 111
结果如下:
300001 101
300001 102
300002 104
300002 105
300003 107
300003 108
------解决方案--------------------select * from TopSales a
where RefKey in (select top 2 RefKey from TopSales where CategoryID = a.CategoryID )
------解决方案--------------------select * from 表 t where RefKey in (select top 2 RefKey from 表 where CategoryID=t.CategoryID order by RefKey asc)