Ниже приведен пример для BigQuery Standard SQL
#standardSQL
WITH `project.dataset.table` AS (
SELECT 'a' user, 10 ranking UNION ALL
SELECT 'b', 2 UNION ALL
SELECT 'a', 12 UNION ALL
SELECT 'a', 14 UNION ALL
SELECT 'c', 22 UNION ALL
SELECT 'd', 21
)
SELECT
user,
MAX(ranking) AS ranking_max,
STRING_AGG(CAST(ranking AS STRING)) ranking_list
FROM `project.dataset.table`
GROUP BY user
с результатом
Row user ranking_max ranking_list
1 a 14 10,12,14
2 b 2 2
3 c 22 22
4 d 21 21
Примечание: если вам нужно заказать ranking_list
- вы можете использовать ORDER BY
в STRING_AGG
, как показано ниже
STRING_AGG(CAST(ranking AS STRING) ORDER BY ranking) ranking_list