0

我有表 part_volume 列部分,volume_1,volume_2,volume_3,volume_4,volume_5,volume_6 列。

表有如下数据:

PART      VOLUME_1 VOLUME_2 VOLUME_3 VOLUME_4 VOLUME_5 VOLUME_6               
--------- -------- -------- -------- -------- -------- --------
camera        1500        0        0        0     3000        0

我想将数据显示为

PART      VOLUME_1 VOLUME_2 VOLUME_3 VOLUME_4 VOLUME_5 VOLUME_6               
--------- -------- -------- -------- -------- -------- --------
camera        1500     1500     1500     1500     3000     3000    

我怎样才能在 oracle 中实现这一点?

谢谢并恭祝安康,

洛帕

4

1 回答 1

0

所以如果当前值是,只保留先前的值0

如果是这样:

select part,
       volume_1,
       coalesce(volume_2, volume_1) volume_2,
       coalesce(volume_3, volume_2, volume_1) volume_3,
       coalesce(volume_4, volume_3, volume_2, volume_1) volume_4,
       coalesce(volume_5, volume_4, volume_3, volume_2, volume_1) volume_5,
       coalesce(volume_6, volume_5, volume_4, volume_3, volume_2, volume_1) volume_6
  from (select part,
               volume_1,
               case volume_2 when 0 then to_number(null) else volume_2 end volume_2,
               case volume_3 when 0 then to_number(null) else volume_3 end volume_3,
               case volume_4 when 0 then to_number(null) else volume_4 end volume_4,
               case volume_5 when 0 then to_number(null) else volume_5 end volume_5,
               case volume_6 when 0 then to_number(null) else volume_6 end volume_6
          from data);

是否可能为空,如果是,规则是否与零相同?

于 2013-02-15T11:46:33.493 回答