BigQuery的;仅从字符串中提取数字

时间:2015-02-05 08:35:36

标签: split extract google-bigquery

我的数据看起来像1x1000向量,输入数量可变。有时它只是年龄,但有时它们会增加重量和状态ID。

85 age
15 age; 68 Weight
25 age; 80 Weight; 02 Alaska
72 Weight; 50 Wyoming

我想得到的只是数字 - 即

85
15 68 
25 80 02 
72 50

我使用SPLIT并没有那么多成功,因为这给了我超过2000行而不是1000行。所以我不知道该怎么做。 除非可以合并SPLIT并告诉我在拆分之前有多少信息点。即

85    1
15    2
68    2
25    3
80    3

2 个答案:

答案 0 :(得分:2)

您可以使用REGEXP_REPLACE

SELECT REGEXP_REPLACE("25 age; 80 Weight; 02 Alaska",'[^0-9 ]','')

详细了解Regular Expression functions

答案 1 :(得分:1)

为了完整性 - 这就是你如何使用SPLIT在分割前获得信息点数的结果:

select left(xs, 2), count(xs) within record from(
select split(x, ";") xs from 
(select "85 age" as x),
(select "15 age; 68 Weight" as x),
(select "25 age; 80 Weight; 02 Alaska" as x),
(select "72 Weight; 50 Wyoming" as x))
相关问题