获取某几个分类下的前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;

posted @ 2013-10-17 17:00  红鲤鱼与驴与绿鲤鱼  阅读(282)  评论(0编辑  收藏  举报