获取某几个分类下的前N条数据 mssql语句

方案1:

(SELECT top 10 *
  FROM 表 where type=3
  ) UNION ALL
  (SELECT top 10 *
  FROM 表 where type=4
  )
  UNION ALL
  (SELECT top 10 *
  FROM 表 where type=5
  )

方案2:

select * from
 (select *,row_number()over(partition by type order by id desc) as RN from 表 t
 where type in (3,4,5)
 )a where rn <=10;

原文地址:https://www.cnblogs.com/yhdkzy/p/3374501.html