0

part、volume_1、volume_2、volume_3、volume_4、volume_5、volume_6列の列を持つテーブルpart_volumeがあります。

テーブルには次のようなデータがあります。

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    

どうすればオラクルでこれを達成できますか?

よろしくお願いいたします。

ロパ

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 に答える