需要使用 bigquery 查找字符串
Need to find string using bigquery
我们有以下字符串列和以下数据
我想找到字符串列中存在的 Null 计数意味着 how many times null value('') present in front of id column present in select statement
使用大查询。
不要使用字符串位置。
预期输出:
count of null ('')id =3
1st row,2nd row and 5th row
我们的想法是将所有字符串统一为您可以使用 like = "%''asid%" 或正则表达式查询的内容
首先用''
替换所有空格
将“[”、“]”替换为“”。
使"或'的使用保持一致。
然后点赞查询
例如:
select 1 from (select replace(replace(replace(replace('select "" as do, "" as [id] form table1',' ',''),'[',''),']',''),'"',"'") as tt)
where tt like ("%''asid%")
这不是一个“聪明”的想法,但它很简单。
更好的办法是将查询列保存在重复列 '"" as id' 中,并将 table 保存在另一列中。
您不需要保存 'select' 和 'from' 这样您就可以轻松查询并且 assemble 从数据中查询。
如果我没理解错的话,你要统计''
在string
栏中出现的次数。
如果是这样,你可以使用regexp_extract_all()
:
select t.*,
(select count(*)
from unnest(regexp_extract_all(t.string, "''")) u
) as empty_string_count
from t;
以下适用于 BigQuery 标准 SQL
#standardSQL
SELECT
FORMAT(
"count of null ('')id = %d. List of id is: %s",
COUNT(*),
STRING_AGG(CAST(ID AS STRING))
) AS output
FROM `project.dataset.table`
WHERE REGEXP_CONTAINS(String, r"(?i)''\s+(?:as|)\s+(?:id|\[id\])")
如果应用于您问题中的示例数据 - 输出是
Row output
1 count of null ('')id = 3. List of id is: 1,2,5
我们有以下字符串列和以下数据
我想找到字符串列中存在的 Null 计数意味着 how many times null value('') present in front of id column present in select statement
使用大查询。
不要使用字符串位置。
预期输出:
count of null ('')id =3
1st row,2nd row and 5th row
我们的想法是将所有字符串统一为您可以使用 like = "%''asid%" 或正则表达式查询的内容
首先用''
替换所有空格
将“[”、“]”替换为“”。
使"或'的使用保持一致。
然后点赞查询
例如:
select 1 from (select replace(replace(replace(replace('select "" as do, "" as [id] form table1',' ',''),'[',''),']',''),'"',"'") as tt)
where tt like ("%''asid%")
这不是一个“聪明”的想法,但它很简单。
更好的办法是将查询列保存在重复列 '"" as id' 中,并将 table 保存在另一列中。
您不需要保存 'select' 和 'from' 这样您就可以轻松查询并且 assemble 从数据中查询。
如果我没理解错的话,你要统计''
在string
栏中出现的次数。
如果是这样,你可以使用regexp_extract_all()
:
select t.*,
(select count(*)
from unnest(regexp_extract_all(t.string, "''")) u
) as empty_string_count
from t;
以下适用于 BigQuery 标准 SQL
#standardSQL
SELECT
FORMAT(
"count of null ('')id = %d. List of id is: %s",
COUNT(*),
STRING_AGG(CAST(ID AS STRING))
) AS output
FROM `project.dataset.table`
WHERE REGEXP_CONTAINS(String, r"(?i)''\s+(?:as|)\s+(?:id|\[id\])")
如果应用于您问题中的示例数据 - 输出是
Row output
1 count of null ('')id = 3. List of id is: 1,2,5