Вы можете использовать json_table()
, чтобы развернуть массивы как строки, а затем json_arrayagg()
, чтобы агрегировать обратно:
select s.name, json_arrayagg(t.cust) customers
from source_type_daily_metrics s
cross join json_table(s.customers, '$[*]' columns (cust int path '$')) t
where s.merchant_id = 29 and date >= current_date - interval 30 day
group by s.name
Если в массивах есть повторяющиеся идентификаторы клиентов, и вы хотите, чтобы в набор результатов, то вам нужен дополнительный уровень агрегирования (поскольку, к сожалению, json_arrayagg()
не поддерживает distinct
):
select name, json_arrayagg(cust) customers
from (
select distinct s.name, t.cust
from source_type_daily_metrics s
cross join json_table(s.customers, '$[*]' columns (cust int path '$')) t
where s.merchant_id = 29 and date >= current_date - interval 30 day
) t
group by s.name