Использование STRING_AGG()
:
WITH table AS (
SELECT 'test' u_id, STRUCT(1 AS id) AS key, [STRUCT('hey' AS cmnt)] AS tre, 3 cts
UNION ALL
SELECT 'test', STRUCT(1), [STRUCT('you')], 2
UNION ALL
SELECT 'test', STRUCT(1), [STRUCT(CAST(null AS STRING))], 1
)
SELECT rep.key.id as id, STRING_AGG(te.cmnt, ', ' ORDER BY cts DESC) AS comments
FROM `table` rep, UNNEST(tre) as te
WHERE u_id LIKE 'test'
GROUP BY id