我有一個文本欄位,它是一個逗號分隔的檔案。記錄看起來像這樣
SKU Info
123 Common: tshirt
345 common: jeans, color: green
567 common: tshirt, common: jeans, color: blue
我試圖將這些放入陣列中,但結合第一個單詞相同的位置。IE:對于上面的記錄 3 (567),陣列欄位將是
common: tshirt, jeans
color: blue
我目前的查詢:
select array(select trim(val) from unnest(split(trim(infos, ''))) val) as testing
回報
567 common: jeans
567 common: tshirt
567 color: blue
任何見解或幫助將不勝感激。謝謝!
uj5u.com熱心網友回復:
考慮以下方法
select sku, array(
select any_value(split(trim(val), ':')[offset(0)]) || ': ' ||
string_agg(split(trim(val), ':')[offset(1)], ', ')
from unnest(split(trim(info, ''))) val
group by split(trim(val), ':')[offset(0)]
) as testing
from your_table
如果應用于您問題中的樣本資料 - 輸出是

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/315962.html
標籤:数组 谷歌-bigquery
