2017-01-10 32 views
1

有誰知道如何同時使用多個FLATTEN函數和Table_date_range?現在我只能得到一天的數據,但我想要獲得所有可用的數據。有沒有辦法做到這一點?谷歌大查詢拼合表和使用table_range函數

select 
Date,COUNT(DISTINCT FULLVISITORID),hits.product.v2ProductCategory 
FROM FLATTEN((FLATTEN (table, hits.product.v2ProductCategory)) ,customDimensions.value) 
group by Date 
,hits.product.v2ProductCategory 

謝謝

回答

2

嘗試以下(未測試)

SELECT 
    DATE, 
    COUNT(DISTINCT FULLVISITORID), 
    hits.product.v2ProductCategory 
FROM FLATTEN(FLATTEN (
    (SELECT * 
    FROM TABLE_DATE_RANGE([aaprod-20160309:112099209.ga_sessions_], 
     TIMESTAMP('2016-07-25'), 
     TIMESTAMP('2016-07-27')) 
), hits.product.v2ProductCategory), customDimensions.value 
) 
GROUP BY 
    DATE, 
    hits.product.v2ProductCategory 
+0

非常感謝米哈伊爾。它適用於Google Big query中的我。但是,當我將查詢放入Tableau中時,出現「Syntax error:Expected」]錯誤,但在[1:599]處得到了「:」。我想我必須使用標準的SQL而不是傳統的SQL,如果我想把查詢放在Tableau中。 – Rachel

+0

標準SQL是與BigQuery交互的首選方言。另請參見[Tableau的BigQuery支持頁面](https://onlinehelp.tableau.com/current/pro/desktop/en-us/examples_googlebigquery.html)和[標準SQL參考](https://cloud.google。 COM /大量查詢/文檔/參考/標準SQL /)。 –

+0

完全同意Elliott。同時,如果有關於傳統SQL功能的具體問題 - 我認爲提供直接答案仍然有意義。只要問題的背景不明確/可用 - 就像最初的這個問題一樣 - 只是建議遷移到標準SQL對我來說沒什麼意義 - 這就是爲什麼我沒有這麼做。但仍然 - 完全同意Elliott和他的評論!標準SQL是處理的首選方式(vs Legacy):o)BigQuery –

5

您應該使用標準的SQL來代替。例如,

#standardSQL 
SELECT 
    Date, 
    COUNT(DISTINCT FULLVISITORID), 
    product.v2ProductCategory, 
    customDimension.value 
FROM `aaprod-20160309.112099209.ga_sessions_*` AS t 
    CROSS JOIN UNNEST(hits) AS hit 
    CROSS JOIN UNNEST(t.customDimensions) AS customDimension 
    CROSS JOIN UNNEST(hit.product) AS product 
GROUP BY 1, 3, 4; 

舊版和標準SQL之間的差異在migration guide中描述。

+0

嗨Elliott,感謝您的回答。但是,當我運行查詢時,出現錯誤代碼:列名customDimensions不明確。我試圖解決它。但還沒有找到答案。任何想法? – Rachel

+0

我想你可能需要將其更改爲: FROM'aaprod-20160309.112099209.ga_sessions_ *'爲T 和: CROSS JOIN UNNEST(t.customDimensions)AS customDimension –

+0

謝謝你的快速反應。現在是另一個錯誤:無法在類型爲ARRAY >的值上訪問字段v2ProductCategory。我對Google Big Query很陌生,如果我有太多問題,我很抱歉。 – Rachel