更正一下数据不改,只要是select的别的方法.
数据改了就变成结果
    NUll               m
     NUll               n
      NUll              y
a                    lpg
lpg                  u
lpg                    f

解决方案 »

  1.   

    请问,当数据如下:
    b m
    b n
    b y
    a lpg
    b u
    b f楼主希望得到怎样的结果?
      

  2.   

    select id=identity(int),* into #1 from test
    select [co1]=case when co1='b' then
    (select top 1 co2 from #1 where co1='a' and id<a.id order by id desc)   
    else co1 end,co2 from #1 a
      

  3.   

    更正一下数据不改,只要是select的别的方法.
    ----------------------------------------
    什么意思,
    是用select 还是不用select ..?
      

  4.   

    他要的是update吧,select 可以不用 case,
    select ta.*,(select top 1 b from @a tb where tb.c<ta.c and tb.a ='a' and ta.a<>'a' order by tb.c-ta.c desc) from @a ta