I have a table in BigQuery:
|c1|c2|c3|
----------
|a1|'b'|c1|
----------
|a1|'a'|c2|
----------
and I want to group by c1 and array_agg c2 and have a table like below:
c1| c2
--------
a1|'ab'
which concatenate the c2 column and save the alphabetic order. can someone help me with this?
try the following. you can use order by
inside string_agg
. here is the documentation.
select
c1,
string_agg(c2 order by c2) as c2
from yourTable
group by
c1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With