--这样?
declare @t table(序号 int,姓名 varchar(10),籍贯 varchar(10))
insert into @t select  1 ,'张三' ,'广东'
union all select 2, '李四', '广东'
union all select 3, '王二', '广东'
union all select 4, '麻子', '广东'
union all select 5, '李明', '广东'
union all select 6, '刘二', '广东'
union all select 7, '吴号', '江苏'
union all select 8, '李四', '江苏'
union all select 9 ,'刘名', '江苏'
union all select 10, '成名', '江苏'
union all select 11, '李波' ,'江苏'
union all select 12 ,'张三', '江苏'select top 4 姓名,籍贯 from @t where 籍贯='广东'
union all
select top 4 姓名,籍贯 from @t where 籍贯='江苏'

解决方案 »

  1.   

    create table t(序号 int,姓名 varchar(10),籍贯 varchar(10))
    insert into t select  1 ,'张三' ,'广东'
    union all select 2, '李四', '广东'
    union all select 3, '王二', '广东'
    union all select 4, '麻子', '广东'
    union all select 5, '李明', '广东'
    union all select 6, '刘二', '广东'
    union all select 7, '吴号', '江苏'
    union all select 8, '李四', '江苏'
    union all select 9 ,'刘名', '江苏'
    union all select 10, '成名', '江苏'
    union all select 11, '李波' ,'江苏'
    union all select 12 ,'张三', '江苏'
    select * from tselect * from t x where 序号 in(select top 4 序号 from t where 籍贯=x.籍贯)
      

  2.   

    declare @t table(序号 int,姓名 varchar(10),籍贯 varchar(10))
    insert @t select     1,     '张三',   '广东'
    insert @t select 2,     '李四',   '广东'
    insert @t select 3,     '王二',   '广东'
    insert @t select 4,     '麻子',   '广东'
    insert @t select 5,     '李明',   '广东'
    insert @t select 6,     '刘二',   '广东'
    insert @t select        7,     '吴号',   '江苏'
    insert @t select 8,     '李四',   '江苏'
    insert @t select 9,     '刘名',   '江苏'
    insert @t select 10,    '成名',   '江苏'
    insert @t select 11,    '李波',   '江苏'
    insert @t select 12,    '张三',   '江苏'select a.* from @t a,
    (select *,[num]=(select count(1) from @t where 籍贯=a.籍贯 and 序号<=a.序号) from @t a ) b
    where a.序号=b.序号 and b.num<=4
    序号          姓名         籍贯         
    ----------- ---------- ---------- 
    1           张三         广东
    2           李四         广东
    3           王二         广东
    4           麻子         广东
    7           吴号         江苏
    8           李四         江苏
    9           刘名         江苏
    10          成名         江苏(所影响的行数为 8 行)
      

  3.   

    select * from t x where(select count(1) from t where 籍贯=x.籍贯 and 序号<=x.序号)<=4
      

  4.   

    select * from t x where 序号 in(select top 4 序号 from t where 籍贯=x.籍贯)