Below is for BigQuery Standard SQL
#standardSQL
SELECT DISTINCT * EXCEPT(value_1, value_2, grp),
SUM(value_1) OVER(PARTITION BY grp) sum_value_1,
SUM(value_2) OVER(PARTITION BY grp) sum_value_2
FROM (
SELECT *, REGEXP_REPLACE(TO_JSON_STRING(t), r'"(?:value_1|value_2)":.+?[,}]', '') grp
FROM `project.dataset.table` t
)
You can test, play with above using dummy data as in below example
#standardSQL
WITH `project.dataset.table` AS (
SELECT 1 value_1, 2 value_2, 3 value_3, 4 value_4 UNION ALL
SELECT 11, 12, 3, 14 UNION ALL
SELECT 21, 22, 3, 14
)
SELECT DISTINCT * EXCEPT(value_1, value_2, grp),
SUM(value_1) OVER(PARTITION BY grp) sum_value_1,
SUM(value_2) OVER(PARTITION BY grp) sum_value_2
FROM (
SELECT *, REGEXP_REPLACE(TO_JSON_STRING(t), r'"(?:value_1|value_2)":.+?[,}]', '') grp
FROM `project.dataset.table` t
)
with result as
Row value_3 value_4 sum_value_1 sum_value_2
1 3 14 32 34
2 3 4 1 2
Above will work with any number of columns and you don't need to reference them all explicitly - only those columns to be excluded to be explicitly referenced - value_1 and value_2 in this example
REGEXP_REPLACE(TO_JSON_STRING(t), r'"(?:value_1|value_2)":.+?[,}]', '') grp
– Dobby