select id=identity(int,1,1),* into #tmp from [2]
select [1].id,[2].fvalue from [1] a left join #tmp b on a%4+1=b.id

解决方案 »

  1.   

    select a.id,b.Fvalue
    from t1 a join t2 b on (a.id-1)%4+1=(
    select sum(1) from t2 where Fvalue<=b.Fvalue)
    order by a.id
      

  2.   

    --测试--测试数据
    create table t1(Id int)
    insert t1 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 12create table t2(Fvalue char(1))
    insert t2 select 'A'
    union all select 'B'
    union all select 'C'
    union all select 'D'
    go--查询
    select a.id,b.Fvalue
    from t1 a join t2 b on (a.id-1)%4+1=(
    select sum(1) from t2 where Fvalue<=b.Fvalue)
    order by a.idgo
    --删除测试
    drop table t1,t2/*--测试结果
    id          Fvalue 
    ----------- ------ 
    1           A
    2           B
    3           C
    4           D
    5           A
    6           B
    7           C
    8           D
    9           A
    10          B
    11          C
    12          D(所影响的行数为 12 行)--*/
      

  3.   

    create table t1(Id int)
    insert t1 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 12create table t2(Fvalue char(10))
    insert t2 select '你是' --'A'  不行了
    union all select 'B'
    union all select 'C'
    union all select 'D'
    go--查询
    select a.id,b.Fvalue
    from t1 a join t2 b on (a.id-1)%4+1=(
    select sum(1) from t2 where Fvalue<=b.Fvalue)
    order by a.idgo
    --删除测试
    drop table t1,t2但改了t2的值后就不行了
    我要求的是表t2 的第一行的Fvalue是表t1第一行的Fvalue,t2第二行的Fvalue 是t1第二行的Fvalue,依次下去
      

  4.   

    --那就只能用临时表
    select id=identity(int,1,1),Fvalue  into #t from t2
    select a.id,b.Fvalue
    from t1 a join #t b on (a.id-1)%4+1=b.id
    order by a.id
    drop table #t