[英]How can I de-concatenate a string in BigQuery, removing the initial substring that exists in another column?
Someone sent me data that looks like this有人向我发送了如下所示的数据
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 |
As you can see, the Section values are usually prefixed by the Zone name.如您所见, Section值通常以区域名称为前缀。 In other words, someone seems to have concatenated the Zone values with the true Section values.
换句话说,似乎有人将 Zone 值与真正的 Section 值连接起来。 I would like to transform the data to its original state, which should look like this
我想将数据转换为其原始的 state,它应该看起来像这样
|Zone |Section |
|:---------------|:------------------|
|Field Outfield |109 |
|Bleachers |202 |
|Delta Suites |218 A |
|Jim Beam Suites |Terrace 317 |
I would use REGEXP_REPLACE()
, but I don't think you can do it in a vectorized fashion.我会使用
REGEXP_REPLACE()
,但我认为您不能以矢量化方式进行操作。
You simply use REPLACE, it will only remove Zone, if it is there, the TRIM will removes Spaces leading and trailing.您只需使用 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.