2016-11-16 35 views
0

我正在編寫一個查詢來比較今年提交的年份,我在BigQuery中使用此命令string((year(current_date())))
我得到的錯誤" ON clause must be AND of = comparisons of one field name from each table, with all field names prefixed with table name. ."(d.month) = String(Month((order.order_timestamp)))因爲它沒有比較表中的列,而只是使用時間戳的月份。有沒有解決辦法?BigQuery中standardql模式下的年份函數

#standardSQL 
SELECT 
    INTEGER(SUM(order2.demand_amount_usd)), 
    order2.quarter_name, 
    order2.year 
FROM (
    SELECT 
    order1.demand_amount_usd, 
    order1.order_timestamp, 
    d1.quarter_name, 
    d1.year 
    FROM 
    [datamart.order_item_lifecycle] AS order1 
    INNER JOIN EACH [datamart.date_dim] AS d 
    ON 
    (d.month) = STRING(MONTH((order.order_timestamp)))) AS order2 
INNER JOIN EACH [datamart.date_dim] AS d2 
ON 
    d2.year = INTEGER(YEAR(order2.order_timestamp)) 
WHERE 
    order2.year = STRING(YEAR(CURRENT_DATE())) 
GROUP BY 
    order2.year, 
    order2.quarter_name; 

回答

1

的主要問題是在這裏,你是混合標準SQL與傳統的SQL
設置SQL模式爲標準不會奇蹟般地轉化傳統的SQL爲標準SQL。例如 - INNER JOIN EACH,[dataset.table]概念,YEAR(),INTEGER()等都來自傳統SQL並且不支持標準SQL

因此,您實際上需要將代碼轉換爲標準SQL - 詳情請見Migrating from legacy SQL

相關問題