Ниже для BigQuery Standard SQL
#standardSQL
SELECT id, question, STRING_AGG(response, ', ') response
FROM `project.dataset.table`
GROUP BY id, question
Вы можете протестировать, поиграть с выше, используя примеры данных из вашего вопроса, как в примере ниже
#standardSQL
WITH `project.dataset.table` AS (
SELECT 1234 id, 'What did you enjoy the most about your experience with us?' question, 'Delivery' response UNION ALL
SELECT 1234, 'What did you enjoy the most about your experience with us?', 'Customer Service' UNION ALL
SELECT 1234, 'What about our Customer Service could we improve?', 'Response Time' UNION ALL
SELECT 1234, 'What about our Customer Service could we improve?', 'Less Email' UNION ALL
SELECT 1234, 'What other products would you like to see us make?', 'Table' UNION ALL
SELECT 5678, 'What about our Customer Service could we improve?', 'Response Time' UNION ALL
SELECT 5678, 'What about our Customer Service could we improve?', 'Site Navigation' UNION ALL
SELECT 5678, 'What other products would you like to see us make?', 'Bookshelf' UNION ALL
SELECT 5678, 'What other products would you like to see us make?', 'Table' UNION ALL
SELECT 5678, 'What other products would you like to see us make?', 'Chairs' UNION ALL
SELECT 9999, 'What did you enjoy the most about your experience with us?', 'Customer Service' UNION ALL
SELECT 9999, 'What did you enjoy the most about your experience with us?', 'Ease of Assembly' UNION ALL
SELECT 9999, 'What did you enjoy the most about your experience with us?', 'Pricing' UNION ALL
SELECT 9999, 'What about our delivery could we improve?', 'Shipping Time' UNION ALL
SELECT 9999, 'What about our delivery could we improve?', 'Custom Delivery' UNION ALL
SELECT 9999, 'What other products would you like to see us make?', 'Bookshelf'
)
SELECT id, question, STRING_AGG(response, ', ') response
FROM `project.dataset.table`
GROUP BY id, question
-- ORDER BY id, question
с результатом
Row id question response
1 1234 What about our Customer Service could we improve? Response Time, Less Email
2 1234 What did you enjoy the most about your experience with us? Delivery, Customer Service
3 1234 What other products would you like to see us make? Table
4 5678 What about our Customer Service could we improve? Response Time, Site Navigation
5 5678 What other products would you like to see us make? Bookshelf, Table, Chairs
6 9999 What about our delivery could we improve? Shipping Time, Custom Delivery
7 9999 What did you enjoy the most about your experience with us? Customer Service, Ease of Assembly, Pricing
8 9999 What other products would you like to see us make? Bookshelf