2017-05-18 33 views
0

我正在查看一個訪問者在我們網站上的具體操作,以瞭解如何收集一些數據以及如何提取我需要的數據。基本上,當訪問者看到我們網站的某些部分時,會啓動特定的促銷活動,並且我想查看是否收集了這些數據。爲什麼在BigQuery中取消兩個或更多變量時我沒有得到任何結果?

我已經運行下面的代碼來識別訪問者看到的網頁和事件的會話火災:

select fullvisitorid, visitid, date, hitnumber, type, page.pagepath, 
eventinfo.eventcategory, eventinfo.eventlabel, eventinfo.eventaction 
from `big-query-156009.xxxxxx.ga_sessions_*` t, t.hits as hits 
where _table_suffix between "20170511" and "20170511" 
and fullvisitorid = 'xxxxxxxxxxxxxxxxxxxxxxxxxx' 
and visitid = xxxxxxxxx 
order by hitnumber 

這工作完全正常,我可以看到訪客的旅程。我也想在

hits.promotion.promoid, 
hits.promotion.promoname, 
hits.promotion.promocreative, 
hits.promotion.promoposition, 
hits.promotionactioninfo.promoisview, 
hits.promotionactioninfo.promoisclick 

拉我已經試過這使用下面的代碼:當我做這將完全一樣fullvisitorid,visitid,日期

select fullvisitorid, 
visitid, 
date, 
hitnumber, 
type, 
page.pagepath, 
eventinfo.eventcategory, 
eventinfo.eventlabel, 
eventinfo.eventaction, 
promotion.promoId, 
promotion.promoname, 
promotion.promocreative, 
promotion.promoposition, 
promotionactioninfo.promoIsView, 
promotionactioninfo.promoIsclick 
from `big-query-156009.xxxxxx.ga_sessions_*` t, t.hits as hits, 
hits.promotion as promotion 
where _table_suffix between "20170511" and "20170511" 
and fullvisitorid = 'xxxxxxxxxxxxxxxxxxxxxxxxxx' 
and visitid = xxxxxxxxx 
order by hitnumber 

但是和數據集等我沒有得到任何結果。沒有錯誤或任何事情,只是沒有結果

我不完全理解嵌套,所以我假設我只是缺少一些簡單的東西。

有沒有什麼辦法可以在一個查詢中提取所有這些數據,還是需要做子查詢?

謝謝

回答

2

通過使用表,t.hits之間的逗號(加入)操作,和hits.promotion,你正在服用的數組的元素的叉積。這種情況發生的原因是由於其中一個陣列爲空(可能爲hits.promotion),因爲1 * <number of hits> * 0 = 0以後您會得到一個空的結果。爲了得到一個排甚至當陣列中的一個是空的,使用左連接代替,如:

from `big-query-156009.xxxxxx.ga_sessions_*` t 
LEFT JOIN UNNEST(t.hits) as hits 
LEFT JOIN UNNEST(hits.promotion) as promotion 
where ... 
+0

美麗!這工作完美。謝謝Elliott! –

0

,可以幫助您在這些類型的分析的另一種技術是運行如下:

SELECT 
    fullvisitorid fv, 
    visitid v, 
    ARRAY(SELECT AS STRUCT hits.hitnumber, hits.type, page.pagepath, eventinfo.eventcategory, promotion FROM UNNEST(hits) hits ORDER BY hitnumber) hits 
FROM `big-query-156009.xxxxxx.ga_sessions_*` 
WHERE 
1 = 1 
AND EXISTS(SELECT 1 FROM UNNEST(hits) hits WHERE ARRAY_LENGTH(hits.promotion) > 0) 

請注意,UNNESTING進程現在只發生在行級別,而不是CROSS-JOIN。

您也可以使用WHERE子句來篩選出你想要的東西(在這種情況下,我刪除了沒有任何關聯的促銷ID的所有行)也可以僅篩選出某些事件類別標籤如果你想)。

相關問題