问题描述
我有一个页面 URL 列组件,其由 /
分隔.我试图在 BigQuery 中运行 SPLIT()
函数,但它只给出第一个值.我想要特定列中的所有值.
I have a page URL column components of which are delimited by /
. I tried to run the SPLIT()
function in BigQuery but it only gives the first value. I want all values in specific columns.
我不明白如何使用 .
I don't understand how to use the Regexp_extract()
example mentioned in Split string into multiple columns with bigquery.
我需要类似于 REGEX_SPLIT_TO_TABLE(<String>, <DELIMITER>)
的东西,它将单个字符串转换为多列.
I need something similar to REGEX_SPLIT_TO_TABLE(<String>, <DELIMITER>)
which converts a single string into multiple columns.
查询:
SELECT PK,
DATE(TIMESTAMP(CONCAT(SUBSTR(date,1,4),'-',SUBSTR(date,5,2),'-',SUBSTR(date,7,2),' 00:00:00'))) as visit_date,
hits_page_pagePath,
split(hits_page_pagePath,'/')
FROM [Intent.All2mon] limit 100
推荐答案
2018标准SQL更新:
#standardSQL
SELECT SPLIT(path, '/')[OFFSET(0)] part1,
SPLIT(path, '/')[OFFSET(1)] part2,
SPLIT(path, '/')[OFFSET(2)] part3
FROM (SELECT "/a/b/aaaa?c" path)
现在我知道您希望它们位于不同的列中.
Now I understand you want them in different columns.
您提供的查询的替代方法:
An alternative to the query you provided:
SELECT FIRST(SPLIT(path, '/')) part1,
NTH(2, SPLIT(path, '/')) part2,
NTH(3, SPLIT(path, '/')) part3
FROM (SELECT "/a/b/aaaa?c" path)
NTH(X, SPLIT(s))
将提供来自 SPLIT 的第 X 个值.FIRST(s)
与 NTH(1, s)
NTH(X, SPLIT(s))
will provide the Xth value from the SPLIT. FIRST(s)
is the same as NTH(1, s)
这篇关于BigQuery:SPLIT() 只返回一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!