哎,开发平台有限制,不能用存储过程,只能用sql语句实现。

解决方案 »

  1.   

    create table table1(Col1 varchar(10),  Col2 int)insert into table1
    select '0001',   3 union all
    select '0002',   4 union all
    select '0002',   5create table table2(Col1 varchar(10),   Col3 int)insert into table2
    select '0002',    6
    goselect t1.Col1,t1.Col2,
           case when row_number() over(PARTITION by t1.col1 
                                           order by @@servername)=1
                     then t2.Col3
                else null
           end as col3
    from table1 t1
    left join table2 t2
           on t1.Col1 = t2.Col1
    /*
    Col1 Col2 col3
    0001 3 NULL
    0002 4 6
    0002 5 NULL
    */
      

  2.   

    table1 左连接 select a.*,b.Col2 from table2 a ,(select Col1 , min(Col2) as Col2  from table2 group by Col1  ) where a.Col1    =b.Col1