2016-10-18 130 views
0

我試圖從GA中結合自定義維度查詢產品級別的基本產品級別維度,並且我無法獲得它的工作:( 任何幫助和/或建議都非常值得歡迎!(當前查詢低於)BigQuery產品級別自定義尺寸

SELECT 
 
    date, 
 
    hits.product.v2ProductName AS productName, 
 
    hits.product.productSKU AS SKU, 
 
    MAX(IF(hits.product.customDimensions.index=126,hits.product.customDimensions.value, null)) WITHIN hits AS customDimesion126, 
 
    COUNT(hits.transaction.transactionId) 
 
FROM 
 
    TABLE_DATE_RANGE([XXX.ga_sessions_],TIMESTAMP('2016-10-16'), TIMESTAMP('2016-10-16')) 
 

 
WHERE 
 
    hits.transaction.transactionId IS NOT NULL 
 
    
 
GROUP BY 
 
    date, 
 
    productName, 
 
    SKU

+0

什麼是錯誤? – Nebi

+0

@Nebi,有效範圍和無限範圍聚合函數的無效混合 – Arjen

+0

你見過這個過去的問題嗎?您可以根據需要調整答案:http://stackoverflow.com/questions/39998428/select-several-event-params-in-a-single-row-for-firebase-events-stored-in-谷歌/ 40000034。我會看看我是否也可以提出一個查詢。 –

回答

0

我沒有訪問表完全一樣的模式,以便能夠嘗試了這一點,但確實是這樣的查詢工作?您需要啓用standard SQL才能運行它(取消選中「顯示選項」下的「使用傳統SQL」離子「):

SELECT 
    date, 
    hits.product.v2ProductName AS productName, 
    hits.product.productSKU AS SKU, 
    (SELECT value 
    FROM UNNEST(hits.product.customDimensions) 
    WHERE index=126) AS customDimension126, 
    COUNT(*) 
FROM 
    `your-dataset.ga_sessions_*` t, t.hits hits 
WHERE 
    _PARTITION_TIME = '2016-10-16' AND 
    hits.transaction.transactionId IS NOT NULL 
GROUP BY 
    date, 
    productName, 
    SKU; 
0

同樣在這裏 - 我沒有訪問表完全一樣的模式,以便能夠嘗試了這一點 - 所以下面的拍攝在空中:O)

對於BigQuery Legacy SQL - 我想盡可能保留原始查詢

SELECT 
    DATE, 
    productName, 
    SKU, 
    customDimesion126, 
    SUM(cnt) AS transactions 
FROM (
    SELECT 
    DATE, 
    hits.product.v2ProductName AS productName, 
    hits.product.productSKU AS SKU, 
    MAX(IF(hits.product.customDimensions.index=126,hits.product.customDimensions.value, NULL)) WITHIN hits AS customDimesion126, 
    COUNT(hits.transaction.transactionId) WITHIN hits AS cnt 
    FROM 
    TABLE_DATE_RANGE([XXX.ga_sessions_],TIMESTAMP('2016-10-16'), TIMESTAMP('2016-10-16')) 
    WHERE 
    hits.transaction.transactionId IS NOT NULL 
) 
GROUP BY 
    DATE, 
    productName, 
    SKU, 
    customDimesion126