2016-11-16 44 views
1

用大查詢中的兩個select語句編寫代碼。不知道爲什麼它不承認領域。未找到錯誤Field --> 'd3.fiscal_week_begin_date';你的意思是'fiscal_week_begin_date'在SQL查詢中雙擊select

SELECT 
    * 
FROM 
    [acquisition.acquisition_program_cost_summary] as test, 
    (
    SELECT 
    d.fiscal_week_begin_date AS fiscal_week_begin_date, 
    d.fiscal_week_end_date AS fiscal_week_end_date 
    FROM 
    datamart.date_dim as d 
    WHERE 
    d.week_of_fiscal_year =30) as d3 
WHERE 
    test.created_timestamp >= d3.fiscal_week_begin_date 
    AND test.created_timestamp <= d3.fiscal_week_end_date; 

回答

2

BigQuery中的逗號(,)並不代表JOIN而是UNION ALL
所以,最有可能你的意思做JOIN像下面
請注意,您應該切換到BigQuery Standard SQL

SELECT * 
FROM acquisition.acquisition_program_cost_summary as test 
JOIN (
    SELECT 
    d.fiscal_week_begin_date AS fiscal_week_begin_date, 
    d.fiscal_week_end_date AS fiscal_week_end_date 
    FROM datamart.date_dim as d 
    WHERE d.week_of_fiscal_year = 30 
) as d3 
ON test.created_timestamp >= d3.fiscal_week_begin_date 
AND test.created_timestamp <= d3.fiscal_week_end_date 
+0

謝謝米哈伊爾。我同意你的看法,並嘗試過這些代碼,但它給出了錯誤。 – SAM244776

+0

ON子句必須與每個表中一個字段名稱的AND比較,所有字段名稱都以表名爲前綴。這裏是錯誤 – SAM244776

+0

你應該切換到標準SQL!你在Web UI中運行/測試它嗎?請參閱我的回答中的鏈接 –