使用 BigQuery 计算数字字符串中数字的出现次数
Count the number of occurrence of a number in string of numbers using BigQuery
我有一个要求,我想使用 Google Bigquery 计算特定数字在数字字符串中出现的次数。
例如
考虑以下方法
select raw_data,
( select count(*)
from unnest(split(raw_data)) el
where el = '1'
) as appearances
from your_table
如果应用于您问题中的示例数据 - 输出为
另一种选择是
select raw_data,
array_length(regexp_extract_all(raw_data, r'\b1\b')) as appearances
from your_table
输出相同,显然
我有一个要求,我想使用 Google Bigquery 计算特定数字在数字字符串中出现的次数。
例如
考虑以下方法
select raw_data,
( select count(*)
from unnest(split(raw_data)) el
where el = '1'
) as appearances
from your_table
如果应用于您问题中的示例数据 - 输出为
另一种选择是
select raw_data,
array_length(regexp_extract_all(raw_data, r'\b1\b')) as appearances
from your_table
输出相同,显然