简体   繁体   English

Bigquery从表中选择任何列包含'FINISHED'

[英]Bigquery Select from table where any column contains 'FINISHED'

I have table in bigquery which has over 100 columns and has more than 70 Million row. 我在bigquery中有一个表,它有100多个列,行数超过7000万。 I want to find out if I can write a query to extract rows where any of the column contains a value 'FINISHED'. 我想知道我是否可以编写一个查询来提取任何列包含值'FINISHED'的行。

Below is for BigQuery Standard SQL Should be good start for you :) 下面是BigQuery标准SQL应该是你的好开始:)

#standardSQL
SELECT <columns to output> 
FROM yourTable AS t
WHERE REGEXP_CONTAINS(LOWER(TO_JSON_STRING(t)), 'finished')

You can test/play with it with below dummy data 您可以使用以下虚拟数据测试/播放它

#standardSQL
WITH yourTable AS (
  SELECT 'a' AS x, 'b' AS y, 'c' AS z UNION ALL
  SELECT 'finished', '', '' UNION ALL
  SELECT '', 'Bigquery Select from table where any column contains "FINISHED"','' UNION ALL
  SELECT '', '', 'aaa' UNION ALL
  SELECT 'finished', 'bbb', 'finished' 
)
SELECT * 
FROM yourTable AS t
WHERE REGEXP_CONTAINS(LOWER(TO_JSON_STRING(t)), 'finished')   

Update 更新

Note: if you have your search word as a part of at least one column name - above will return all rows! 注意:如果您将搜索词作为至少一个列名的一部分 - 上面将返回所有行! To address this - you would need to invest a little bit more coding 要解决这个问题 - 你需要投入更多的代码

For example, for simple schema (with no record or repeated) this would be a 例如,对于简单的模式(没有记录或重复),这将是一个

#standardSQL
SELECT <columns to output>  
FROM yourTable AS t
WHERE (SELECT COUNTIF(SPLIT(zzz, ':')[SAFE_OFFSET(1)] LIKE '%finished%') 
  FROM UNNEST(SPLIT(SUBSTR(LOWER(TO_JSON_STRING(t)),2,LENGTH(TO_JSON_STRING(t))-2))) AS zzz
  ) > 0   

You can test this with below 您可以使用下面的测试

#standardSQL
WITH yourTable AS (
  SELECT 'a' AS x, 'b' AS y, 'c' AS col_finished UNION ALL
  SELECT 'finished', '', '' UNION ALL
  SELECT '', 'Bigquery Select from table where any column contains "FINISHED"','' UNION ALL
  SELECT '', '', 'aaa' UNION ALL
  SELECT 'finished', 'bbb', 'finished' 
)
SELECT * 
FROM yourTable AS t
WHERE (SELECT COUNTIF(SPLIT(zzz, ':')[SAFE_OFFSET(1)] LIKE '%finished%') 
  FROM UNNEST(SPLIT(SUBSTR(LOWER(TO_JSON_STRING(t)),2,LENGTH(TO_JSON_STRING(t))-2))) AS zzz
  ) > 0  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Bigquery SELECT * FROM表,其中column =&#39;string&#39;不返回任何值 - Bigquery SELECT * FROM table where column = 'string' not returning any values 选择列包含任何子查询结果的行 - Select Rows Where A Column Contains Any Result From A SubQuery SQL 选择行,其中列包含字符串中的任何单词 - SQL select rows where column contains any of word from string SQL从表中选择,其中列包含特定的字符串 - SQL select from table where column contains specific strings BigQuery:选择列值包含字符串的行 - BigQuery: select rows where column value contains string BigQuery 标准 SQL SELECT 行 WHERE 字段包含来自另一个表字段的单词 - BigQuery Standard SQL SELECT rows WHERE field contains words from another table field 如何选择表的列名,其中列数据的值中包含“%”? - How to select the column names of a table where column data contains '%' in the values? 如何从SQL的表中选择,其中一列中的元素仅包含另一列的特征,而另一列本身又包含两个特征? - How to select from a table in SQL where element in a column contains only one feature of another column which in turn contains two features in itself? SQL Server SELECT 其中任何列包含“x” - SQL Server SELECT where any column contains 'x' SQL-从表中选择所有行,其中一列仅包含数字 - SQL - select all rows from table where a column contains only digits
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM