Search code examples
google-bigquerystring-agg

How to use String_agg in bigquery


I have a list of codes for same IDs with ranking, I want to have these codes in a coma separated way by there rank in ASC order like (71,49,490,41,61,42,62,614,615,621), when I am using string_agg(code,"," ORDER BY rank_) it is showing below error:

Error Msg

List:

List


Solution

  • You need to CAST your int into string.

    string_agg(CAST(code as STRING),"," ORDER BY rank_)