3

n列とn列のテーブルがあります。列名の一部は次のとおりです。

c, c2,c3,c4,c5  , c25

sample data
c1    c2     c3   c4  c5  (consider only 5 in this case)
x     y      z    z  y
x     y
x
a     b     j     k
a     c      g    h  i
k     l      m    n  o

ここで、op=上記のデータの右側のサンプルopからのnullではない2番目の値

z
x
x  (special case as no data left of x)
j
h
n 

COALESCE広告を使用できません私は最初ではなくnullではなく2番目が必要です

誰かがこのクエリで私を助けることができますか

4

2 に答える 2

3

これは、より複雑なcaseステートメントで行うことができます。

select (case when c5 is not null
             then coalesce(c4, c3, c2, c1)
             when c4 is not null
             then coalesce(c3, c2, c1)
             when c3 is not null
             then coalesce(c2, c1)
             else c1
        end)
. . .
于 2012-12-04T18:48:51.283 に答える
1

何かのようなもの:

 select nvl2(c5,c4,nvl2(c4,c3,nvl2(c3,c2,c1))) result
 from   my_table

未検証。

于 2012-12-04T18:27:16.640 に答える