简体   繁体   English

如何在 BigQuery 中取消连接字符串,删除另一列中存在的初始 substring?

[英]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.

相关问题 如何在 BigQuery 中编写条件 string_agg 函数? - How can I write a conditional string_agg function in BigQuery? 提取 substring 并在 Bigquery 列中获取第二个值 - Extract a substring and take second value in a Bigquery Column 在 bigquery 中,如何检查一个数组中的至少一个元素是否在另一个数组中? - In bigquery how can I check if at least one elemnt from one array is in another array? 使用 bigquery 中具有字符串列的另一个表更新 bigquery 中的结构列 - Update a struct column in bigquery using another table in bigquerry having string columns 如何通过在 bigquery sql 中进行分组字符串比较来返回同一列中字符串值的差异? - How to return difference in string values from the same column by doing a grouped string comparison in bigquery sql? 如何在 BigQuery 中检索 IP 地址的地理位置信息? - How I can retrieve geolocation info for an IP Address in BigQuery? 在 BigQuery 中删除另一列后无法添加列 - Cannot add a column after deleting another column in BigQuery 如何将带有嵌套分隔符的列拆分为 Bigquery SQL 中的结构列表? - How can I split a column with nested delimiters into a list of STRUCTs in Bigquery SQL? 如何根据 BigQuery 中另一列的条件显示值的计数 - How to show a count of values based on condition of another column in BigQuery 通过在 golang 中删除 substring 将字符串分成两部分 - Splitting string in 2 parts by removing substring in golang
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM