如果单独找某一类的可以用如下语句: select top percent 70 * from B where classId=‘A类’
但是现在类别很多,一条一条写太多,如何用一个语句能搞定?
熟悉的朋友帮忙啊。谢谢!!
------解决方案--------------------
SQL code
select a.classid,a.count,b.* from A表 a inner join(
select *,row_number()over(partition by classid order by newid())rn from B表
)b on a.classid=b.classid
where b.rn<(select count(*)*0.7 from B表 where classid=b.classid)
------解决方案--------------------
SQL code
select distinct n.* from B m
cross apply(select top percent 70 * from B where classid=m.classid) n
------解决方案--------------------
------解决方案-------------------- 各位请注意一点:select top percent 70 * from B where classId=‘A类’
这个百分比写的有点问题 修正: select top 70 percent * from B where classId=‘A类’