Is there a way to selectively choose what to put inside an array using ARRAY_AGG in BQ? I have the following table where I'm trying to put deferred cases into an array nested under the respective final case.
case_id status date primary_date primary_case_id primary_status
abc123 deferred 2022-05-01 2022-08-01 ghi789 final
def456 deferred 2022-07-01 2022-08-01 ghi789 final
ghi789 final 2022-08-01 2022-08-01 ghi789 final
jkl123 deferred 2022-10-01 2022-12-01 mno456 final
mno456 final 2022-12-01 2022-12-01 mno456 final
But I get something like this when using ARRAY_AGG where the final case is also included in the array.
primary_date primary_case_id primary_status deferred_cases
2022-08-01 ghi789 final case_id status date
ghi789 final 2022-08-01
def456 deferred 2022-07-01
abc123 deferred 2022-05-01
2022-12-01 mno456 final case_id status date
mno456 final 2022-12-01
jkl123 deferred 2022-10-01
Is there a way to remove the final cases from the array to get the result below?
primary_date primary_case_id primary_status deferred_cases
2022-08-01 ghi789 final case_id status date
def456 deferred 2022-07-01
abc123 deferred 2022-05-01
2022-12-01 mno456 final case_id status date
jkl123 deferred 2022-10-01
