Ниже для BigQuery Standard SQL
#standardSQL
SELECT a, b,
(SELECT STRING_AGG(c ORDER BY c) FROM UNNEST(c_distinct) c) c,
(SELECT STRING_AGG(d ORDER BY d) FROM UNNEST(d_distinct) d) d
FROM (
SELECT a, b,
ARRAY_AGG(DISTINCT c) AS c_distinct,
ARRAY_AGG(DISTINCT d) AS d_distinct
FROM `project.dataset.table`
GROUP BY a, b
)
вы можете протестировать, поиграть с выше, используя примеры данных из вашего вопроса, как в примере ниже
#standardSQL
WITH `project.dataset.table` AS (
SELECT '09-10-2019' a, 1 b, 'math' c, 'social' d UNION ALL
SELECT '09-10-2019', 1, 'math', 'science' UNION ALL
SELECT '09-10-2019', 1, 'math', 'science'
)
SELECT a, b,
(SELECT STRING_AGG(c ORDER BY c) FROM UNNEST(c_distinct) c) c,
(SELECT STRING_AGG(d ORDER BY d) FROM UNNEST(d_distinct) d) d
FROM (
SELECT a, b,
ARRAY_AGG(DISTINCT c) AS c_distinct,
ARRAY_AGG(DISTINCT d) AS d_distinct
FROM `project.dataset.table`
GROUP BY a, b
)
с результатом
Row a b c d
1 09-10-2019 1 math science,social