简体   繁体   English

如何在 BigQuery 表的 450 列中找到值“-32767”?

[英]How to find the value "-32767" in 450 columns in a BigQuery table?

I have a BigQuery table with 450 columns and millions of rows.我有一个包含 450 列和数百万行的 BigQuery 表。 As can be expected, the table has columns of all types like datetime, date, integer, numeric and string.正如所料,该表包含所有类型的列,例如日期时间、日期、integer、数字和字符串。 I want to know which column contains the value "-32767".我想知道哪一列包含值“-32767”。 Is there a way to accomplish this in BigQuery ?有没有办法在BigQuery中完成此操作?

Consider below考虑以下

create temp function  extract_keys(input string) returns array<string> language js as """
  return Object.keys(JSON.parse(input));
  """;
create temp function  extract_values(input string) returns array<string> language js as """
  return Object.values(JSON.parse(input));
  """;
select col, count(*) cnt
from your_table t,
unnest([struct(to_json_string(t) as json)]),
unnest(extract_keys(json)) col with offset
join unnest(extract_values(json)) val with offset
using(offset)
where val = '-32767'
group by col    

this will give you output like below这会给你 output 如下

在此处输入图像描述

Where col3, col2 are columns that have -32767 value and 4,1 is how many rows involved respectively其中 col3、col2 是具有-32767值的列,4,1 分别是涉及的行数

How can I modify it and give it a subset of columns where I expect the value can be?我如何修改它并为其提供我期望值的列的子集?

Assuming you want to limit "search" to only col1 and col3 - use below假设您想将“搜索”限制为仅col1col3 - 请在下面使用

select col, count(*) cnt
from your_table t,
unnest([struct(to_json_string((select as struct col1, col3 from unnest([t]))) as json)]),
unnest(extract_keys(json)) col with offset
join unnest(extract_values(json)) val with offset
using(offset)
where val = '-32767'
group by col    

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

相关问题 Bigquery 将列添加到表架构 - Bigquery add columns to table schema 查找谁在 BigQuery 中创建了表 - Find who created a table in BigQuery 在 Google BigQuery SQL 中,当左连接到另一个表时,如何找到特定列的最小值? - How do you pull find the min value of a specific column, when left joined to another table, in Google BigQuery SQL? 如何使用 sql 在 BigQuery 表中查找缺失的日期 - How to find missing dates in BigQuery table using sql 如何创建表编号列使用 python 到 bigquery load_table_from_dataframe - how to create table number columns use python to bigquery load_table_from_dataframe 如何在 BigQuery 中引用匿名列? - How to reference anonymous columns in BigQuery? StandardSQL BigQuery 值从一个数组中的键值对到单独的列中。 如何? - StandardSQL BigQuery values from key:value pairs within an Array into separate columns. How? BigQuery 仅返回前 500 列。 如何查看全表数据? - BigQuery only return first 500 columns. How can I view the full table data? 当使用 Javascript UDF 的 BigQuery 中的值低于零时,如何使用多列条件进行运行总计? - How to make running total using multiple columns condition when value below zero in BigQuery using Javascript UDF? Bigquery 查找 SQL 有多少表数据在活动存储或长期存储中 - Bigquery find with SQL how much data of a table is in Active storage or Long term Storage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM