gpt4 book ai didi

sql查询以在表中查找第二个非空值(oracle)

转载 作者:行者123 更新时间:2023-12-01 12:48:58 29 4
gpt4 key购买 nike

我有一个表,它有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 = 右侧的第二个非空值上述数据的示例操作

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

不能使用 COALESCE 广告我需要第二个不是空不是第一个

谁能帮我解决这个问题

最佳答案

您可以使用更复杂的 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)
. . .

关于sql查询以在表中查找第二个非空值(oracle),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13709091/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com