我在下面的链接中描述了相同的问题,但是它已提供给sql server,但我需要Hana db的解决方案move cells left in sql if left contains null and right contains value
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
指的是唯一地指定每一行的列或列组。