Table_A  中多一列R放结果数据

解决方案 »

  1.   

    用decode函数可以解决这样的多选问题,在这里可以这样:
    先建立一个子查询:
    select t.*,'a' f1 from Table_A t where t.Value>0.05
    union all
    select t.*,'b' f1 from Table_A t where t.Value<-0.05
    union all
    select t.*,'c' f1 from Table_A t where t.Value>=-0.05 and t.Value<=0.05然后就可以用连接来做了呀
    select l.date,decode(ll.f1,'a',-l.value,'b',l.value,null)
    from Table_B l,
    (select t.*,'a' f1 from Table_A t where t.Value>0.05
    union all
    select t.*,'b' f1 from Table_A t where t.Value<-0.05
    union all
    select t.*,'c' f1 from Table_A t where t.Value>=-0.05 and t.Value<=0.05
    ) ll
    where l.Date=ll.Data
      

  2.   

    decode函数的用法可以查sql reference 这本书,挺好的,如果你日期用的是日期型的话,连接时不要忘了用trunc函数去截取其整天,否则如果time部分不一样可能会出问题,具体的用法你也可以看sql reference 这本书的。具体格式是trunc(l.date,'dd')=trunc(ll.date,'dd'),如果用的是字符串那就无所谓了
      

  3.   

    selec a.date,case 
                 when a.value > 0.05 then - b.value 
                 when a.value <-0.05 then b.value
                 else null end value
    from a,b
    where a.date = b.date