答案 0 :(得分:1)
这样的事情应该会让你朝着正确的方向前进。忽略前 2 个 CTE,因为它们只是复制您的示例数据。
with
-- recreating sample data
temp as (
select 5046528 as LineID, 'Saturday' as positions, 12 as starttime, 23 as endtime union all
select 5046528, 'Wednesday', 0, 15
),
-- formatting to recreate sample data structure
data as (
select LineID, array_agg(struct(positions)) as day_part, array_agg(struct(starttime, endtime)) as hour_part
from temp
group by 1
)
-- Logic that is relevant to the question
select
LineID,
string_agg(safe.concat(upper(d.positions),';',h.starttime,';',h.endtime),'|') as new_column
from data, unnest(day_part) d with offset as d_offset, unnest(hour_part) h with offset as h_offset
where d_offset = h_offset -- needed since you are unnesting 2 arrays, this makes sure your records "line up"
group by 1