I'm using standard SQL on BigQuery to create a new table based on certain conditions within an existing table. I have multiple WHEN clauses to support this (as there are several different conditions I'm checking for). What I now want to do is have multiple THEN clauses within those WHEN statements, as I'm aiming to add more than one column.
Specifically, I want to add a concatenation of two existing text fields as one field, and then an aggregated array of three existing fields as one field:
CASE WHEN
# all three match
one_x1 = two_x1 = three_x1 THEN CONCAT( object1_name, ", ", object2_name, ", ", object3_name ) AND ARRAY_AGG(STRUCT(score_one, score_two, score_three))
# one and two match
WHEN one_x1 = two_x1 THEN CONCAT( object1_name, ", ", object2_name ) AND ARRAY_AGG(STRUCT(score_one, score_two))
# one and three match
WHEN one_x1 = three_x1 THEN CONCAT( object1_name, ", ", object3_name ) AND ARRAY_AGG(STRUCT(score_one, score_three))
# two and three match
WHEN two_x1 = three_x1 THEN CONCAT( object2_name, ", ", object3_name ) AND ARRAY_AGG(STRUCT(score_two, score_three))
ELSE
NULL
END
It is the 'AND ARRAY_AGG(STRUCT(xxxxx))' part that does not work, I have also tried using commas to separate the THEN clauses.
Is the only option to repeat the same case statement to separate the THEN clauses individually?
Sample data: sample_data desired outcome for row 1 of sample data: here