我有一张表perfor,有如下字段
ID ,status,campaign
现在要根据上一个月status求下一个月的status,如
ID    status  campaign
0001  1       200701
那么
ID    status  campaign
0001  2       200702
Update语句如何写?谢谢了!

解决方案 »

  1.   

    后一个月的status由前一个月的status决定,
    比如前一个月是1,后一个月是2,
    再比如前一个月是0,后一个月是4
      

  2.   

    后一个月的status由前一个月的status决定,
    比如前一个月是1,后一个月是2,
    再比如前一个月是0,后一个月是4
    --------------------------------
    更不明白了,你说说有什么样的规律吧,或者还是在别的表里保存的!
      

  3.   

    update perfor a set a.status = (select 1 from perfor b 
                                             where a.distid = b.distid 
                                               and a.campaign = '200708'
                                               and b.campaign = '200707'
                                               and b.status in (2,4))
     where exists (select 1 from perfor b 
                         where a.distid = b.distid 
                           and a.campaign = '200708'
                           and b.campaign = '200707'
                           and b.status in (2,4)); 
    我就是要这种语句,但是月份只要符合a.campaign为b.campaign 的后一个月,而不要明确指定月份,因为我所有月份都是这种逻辑。
      

  4.   

     select 1 
     from perfor a,perfor b 
     where a.distid=b.distid and
           a.campaign=b.campaign(+)+1 and
           b.status in(2,4));
      

  5.   

    update perfor a set a.status = (
    select 
    case b.id 
    when 1 then 2 
    when 0 then 4 
    end
    where a.id =b.id 
    and b的月份=a的月份-1)