[英]Count the number of times a string appeared in a delimited field In BIGQUERY
我有一个带有分隔符“->”的数据集,例如:
ROW 1- "Q -> Res -> tes -> Res -> twet"
ROW 2- "rw -> gewg -> tes -> Res -> twet"
ROW 3- "Y -> Res -> Res -> Res -> twet"
我只想计算每一行中“Res”的数量
Output 将是:
ROW 1- 2
ROW 2- 1
ROW 3- 3
我尝试编写以下查询,但它们计数不正确或只计数一次:
countif(distinct(lower(FIELD_NAME) like '%Res%'))
count(split(regexp_extract(FIELD_NAME, '(.*?)Res'), '->'))
(trim(Array_reverse(split(regexp_extract(FIELD_NAME, '(.*?)Res'), '->')))
count(regexp_extract(trim(FIELD_NAME), 'Res'))
count(regexp_contains(trim(FIELD_NAME), 'Res'))
您可以尝试使用REGEXP_EXTRACT_ALL()
考虑以下方法:
select str,
array_length(REGEXP_EXTRACT_ALL(str, r'\sRes\s')) as Res_count
from your_table
Output:
有关使用此 BigQuery 字符串 function 的更多信息,您可以参考此文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.