首页 > 解决方案 > 如何轻松列出 BigQuery 中的列

问题描述

我在 BigQuery 中有一个包含许多列的表。我想在选择查询中列出它的列,但列出所有列很难。

我想做这样

SELECT
  col1,
  col2,
  col3,
  ...
  SOME_METHOD(col30),
  ...
  col50
FROM
 foo.bar;

有什么方法可以轻松编写这样的查询吗?

标签: sqlgoogle-bigquery

解决方案


以下是 BigQuery 标准 SQL

SELECT * EXCEPT(col30), SOME_METHOD(col30)
FROM foo.bar  

或者

SELECT * REPLACE(SOME_METHOD(col30) as col30)
FROM foo.bar  

例如

#standardSQL
WITH `project.dataset.table` AS (
  SELECT 1 col1, 2 col2, 3 col3, 4 col4, 5 col5
)
SELECT * EXCEPT(col3), 2 * col3 AS col3
FROM `project.dataset.table`

结果

Row col1    col2    col4    col5    col3     
1   1       2       4       5       6    

或者

#standardSQL
WITH `project.dataset.table` AS (
  SELECT 1 col1, 2 col2, 3 col3, 4 col4, 5 col5
)
SELECT * REPLACE(2 * col3 AS col3)
FROM `project.dataset.table`

结果

Row col1    col2    col3    col4    col5     
1   1       2       6       4       5    

推荐阅读