SQL查询无法在Google BigQuery上运行

时间:2015-12-27 17:12:03

标签: sql google-bigquery

当我在Google Bigquery上尝试此查询时,出现以下错误:

"SELECT query which references non constant fields or uses aggregation functions or has one or more of WHERE, OMIT IF, GROUP
 BY, ORDER BY clauses must have FROM clause."

发生了什么事?

SELECT fq.ds_id AS ds_id,
       fq.dm_id AS dm_id,
       fq.freq AS freq,
       rc.rec AS rec,
       rd.reg AS reg
FROM dataset.table_fq_ds fq
  INNER JOIN EACH dataset.table_rc_ds rc ON (fq.ds_id = rc.ds_id)
  INNER JOIN EACH dataset.table_rd_ds rd ON (fq.ds_id = rd.ds_id);

1 个答案:

答案 0 :(得分:0)

我希望以下内容有助于排查

第一个SELECT完美地工作,而第二个提供完全相同的错误

“正确”版本

SELECT 
  fq.ds_id AS ds_id,
  fq.dm_id AS dm_id,
  fq.freq AS freq,
  rc.rec AS rec,
  rd.reg AS reg
FROM ( SELECT 1 AS ds_id, 11 AS dm_id, 12 AS freq) fq
INNER JOIN EACH (SELECT 1 AS ds_id, 22 AS rec) rc ON (fq.ds_id = rc.ds_id)
INNER JOIN EACH (SELECT 1 AS ds_id, 33 AS reg) rd ON (fq.ds_id = rd.ds_id);

ds_id   dm_id   freq    rec reg  
    1      11     12     22  33  

有错误的版本 - 仅在第一个INNER中更改:
SELECT ds_id vs SELECT 1 AS ds_id

SELECT 
  fq.ds_id AS ds_id,
  fq.dm_id AS dm_id,
  fq.freq AS freq,
  rc.rec AS rec,
  rd.reg AS reg
FROM ( SELECT 1 AS ds_id, 11 AS dm_id, 12 AS freq) fq
INNER JOIN EACH (SELECT ds_id, 22 AS rec) rc ON (fq.ds_id = rc.ds_id)
INNER JOIN EACH (SELECT 1 AS ds_id, 33 AS reg) rd ON (fq.ds_id = rd.ds_id);  
  

错误:SELECT查询引用非常量字段或使用   聚合函数或者有一个或多个WHERE,OMIT IF,GROUP BY,   ORDER BY子句必须具有FROM子句。