简体   繁体   English

将字符串拆分为 2 列(Bigquery)

[英]Split string into 2 columns (Bigquery)

I need to split ADDRESS LINE into two columns - address number and street.我需要将 ADDRESS LINE 分成两列 - 地址编号和街道。

I have tried the following:我尝试了以下方法:

Select 
REGEXP_EXTRACT_ALL(address_number, r"([0-9]+)"), 
REGEXP_EXTRACT(address_street, r"([a-zA-Z]+)")
From table;

and

Select 
substr(addressline1, 1, 4) as address_number,
substr(addressline1, 6, 30) as address_street,
From table;

However, none of them seem to be ideal because address line does not have strict structure.但是,它们似乎都不理想,因为地址行没有严格的结构。

It can be:有可能:

Adressline1
9666 Northridge Ct.
P.O. Box 8070
369 Peabody Road
83 Mountain View Blvd
3279 W 46th St

I would say to cut it into two parts - and split it after first space but did not find the right way.我会说将它分成两部分 - 并在第一个空格后将其拆分但没有找到正确的方法。

You Can try following code你可以试试下面的代码

with data as 
(select '9666 Northridge Ct.' as add1 Union all
select 'P.O. Box 8070' as add1 Union all
select '369 Peabody Road' as add1 Union all
select '83 Mountain View Blvd' as add1 Union all
select '3279 W 46th St' as add1 )
SELECT
  add1,
REGEXP_EXTRACT_ALL(add1, r'\d+') AS numbers,
REGEXP_REPLACE(add1, r'\d+', '') AS non_numbers
FROM data

output looks like:-输出看起来像:- 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM