2015-12-27 73 views
0

工作當我嘗試在谷歌的BigQuery此查詢,我得到以下錯誤:SQL查詢不是谷歌的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); 

回答

0

我希望下面將有助於排除故障

首先選擇完美的作品,而第二個給了完全相同的錯誤

「正確」 版本

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); 

Error: 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.

+0

你的第二個查詢好像它實際上是正確的錯誤 - AS rec'指現場'ds_id'但沒有按」'選擇ds_id,22給它一個不變的價值或者說它來自哪個表。 –

+0

這就是要點 - 顯示如何引入這樣的錯誤 –

+0

對不起,我不明白你的答案,我不能再看到我的dataset.tables在你的代碼。我不認爲我的查詢沒有問題。我認爲這是一個更大的問題。 – sweeeeeet