select top 5 Id,[Type] from A where [Type] =0
union all
select top 5 Id,[Type] from A where [Type] =1
需求是根据表中的类别(0-3),每个类别都取5条,上面这样的写法(只是模拟先取2个类别)还能优化不?

------解决思路----------------------
用ROW_NUMBER ,你的代码少了排序列啊。不然TOP 5 就是随机取的了
select * from
(select * ,row_number()over(partition by type order by colname) asn from A) as t
where t.n<=5