[英]How can I de-concatenate a string in BigQuery, removing the initial substring that exists in another column?
有人向我發送了如下所示的數據
WITH
foo as (
SELECT "Field Outfield" AS Zone, "Field Outfield 109" AS Section
UNION ALL SELECT "Bleachers" AS Zone, "Bleachers 202" AS Section
UNION ALL SELECT "Delta Suites" AS Zone, "Delta Suite 218 A" AS Section
UNION ALL SELECT "Jim Beam Suites" AS Zone, "Terrace 317" AS Section
)
SELECT * FROM foo
|Zone |Section |
|:---------------|:------------------|
|Field Outfield |Field Outfield 109 |
|Bleachers |Bleachers 202 |
|Delta Suites |Delta Suite 218 A |
|Jim Beam Suites |Terrace 317 |
如您所見, Section值通常以區域名稱為前綴。 換句話說,似乎有人將 Zone 值與真正的 Section 值連接起來。 我想將數據轉換為其原始的 state,它應該看起來像這樣
|Zone |Section |
|:---------------|:------------------|
|Field Outfield |109 |
|Bleachers |202 |
|Delta Suites |218 A |
|Jim Beam Suites |Terrace 317 |
我會使用REGEXP_REPLACE()
,但我認為您不能以矢量化方式進行操作。
您只需使用 REPLACE,它只會刪除 Zone,如果它在那里,TRIM 將刪除空格前導和尾隨。
WITH
foo as (
SELECT "Field Outfield" AS Zone, "Field Outfield 109" AS Section
UNION ALL SELECT "Bleachers" AS Zone, "Bleachers 202" AS Section
UNION ALL SELECT "Delta Suites" AS Zone, "Delta Suite 218 A" AS Section
UNION ALL SELECT "Jim Beam Suites" AS Zone, "Terrace 317" AS Section
)
SELECT Zone, TRIM(REPLACE(Section, Zone, '')) FROM foo
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.