我有一个包含450个列和数百万行的BigQuery表。正如可以预期的那样,该表具有所有类型的列,如日期时间、日期、整数、数字和字符串。我想知道哪一列包含值"-32767“。有没有办法在BigQuery中实现这一点?
发布于 2022-05-11 00:24:59
考虑以下几点
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 这将为您提供如下输出

其中col3、col2是具有-32767值的列,4,1是分别涉及的行数。
,我如何修改它,给它一个列的子集,我希望它的值可以是?
假设您只想将“搜索”限制在col1和col3上-请在下面使用
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 https://stackoverflow.com/questions/72194104
复制相似问题