Hana sql如果左侧包含空值,右侧包含值,则在sql中向左移动单元格

问题描述 投票:0回答:1

我在下面的链接中描述了相同的问题,但是它已提供给sql server,但我需要Hana db的解决方案move cells left in sql if left contains null and right contains value

sql database hana
1个回答
1
投票
嗯。 。 。在Hana中,我认为您可以使用unpivot使用union all,然后使用row_number()和聚合:

select id, max(case when order = 1 then val end) as a, max(case when order = 2 then val end) as b, . . . from (select id, val, row_number() over (partition by id rder by ord) as as from ((select 1 as ord, id, a as val from t) union all (select 2 as ord, id, b as val from t) union all . . . ) t where val is not null ) t group by id;

这里id指的是唯一地指定每一行的列或列组。    
© www.soinside.com 2019 - 2024. All rights reserved.