Hana sql 如果左侧包含 null 且右侧包含值,则将 sql 中的单元格向左移动
Hana sql move cells left in sql if left contains null and right contains value
我遇到了下面 link 中描述的相同问题,但是它已针对 sql 服务器给出,但我需要 Hana 数据库的解决方案
move cells left in sql if left contains null and right contains value
嗯。 . .在 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
指的是唯一指定每一行的列或列组。
我遇到了下面 link 中描述的相同问题,但是它已针对 sql 服务器给出,但我需要 Hana 数据库的解决方案 move cells left in sql if left contains null and right contains value
嗯。 . .在 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
指的是唯一指定每一行的列或列组。