SQL2008r2 怎么查询同一个表内的不同列和不同数量的内容并放在同一张表

下面的语句现在取的值'aa','bb','cc','dd','ee'都是1000,
怎么才能排除province列的北京,湖南,取aa=前1000行,bb=前500行,cc=前1500行,dd=前1100行,ee=前600

use kc1

     select * into #rr

     from

     (select * from tabel1)

     as aaa 

     where  province not in('北京','湖南')

     ORDER BY mdn,labelname,province,city

     select t.*    

     into  kc2..[tabel2]

     from

     (select mdn,labelname,province,city, row_number() 

     over (partition by labelname order by labelname desc)

     rn 

     from #rr) t

     where    rn<=1000

     and   labelname  in('aa','bb','cc','dd','ee')

建议你根据sql的特性去解决,不能给你详细的代码了,https://ask.csdn.net/questions/766185 这里我的回答采纳了,给你完整的sql

兄弟,你的上一个帖子我已经回复你了,省份筛选放里面就可以,至于你的aa=1000,bb=500这种的只能用死方法了

create table temp1(labelname varchar(5),cnt int)
insert into temp1 values('aa',100),('bb',50)

select mdn,labelname,province,city, row_number() over (partition by labelname order by labelname desc) as rn into #pp
from tabel1 A
where a.labelname in('aa','bb','cc','dd','ee') and province not in('北京','湖南')

select a.* from #pp A,Temp1 B
where a.labelname=b.labelname and a.rn<b.cnt

楼主是要这样吗?

union all 比较简单。