2017-01-24 15 views
0

Max機能を使用せずに複数のカスタムディメンションをGBQで使用する方法はありますか? Max関数を使用する私の問題は、max pax_numを保存するだけですが、(Date、product.v2ProductCategory、eCommerceAction.action_type 、product.v2ProductName)のすべての組み合わせの訪問者数を取得したいと考えています。 pax_numは、そのチケットのpaxの数です。私は、これはあなたが探しているものであるかどうかわからGoogle Big Queryで複数のカスタムディメンションを使用する方法

SELECT 
    Date 
    ,count(distinct(concat(FULLVISITORID,cast(visitID as string)))) as visitor 
, product.v2ProductCategory as product_category 

    ,max(if(customDimensions.index=2, customDimensions.value,null)) as dest 
    ,max((if(customDimensions.index=21, customDimensions.value,null))) as pax_num 
,eCommerceAction.action_type as Action_type 

,product.v2ProductName as product_name 
FROM `table` as t 
    CROSS JOIN UNNEST(hits) AS hit 
    CROSS JOIN UNNEST(hit.customDimensions) AS customDimensions 
    CROSS JOIN UNNEST(hit.product) AS product 

GROUP BY 
     Date 
     ,product.v2ProductCategory 
    ,eCommerceAction.action_type 
,product.v2ProductName 
+0

わからない問題を解決追加しかし、あなたは** pax_numの最大値を持つようにしたくないと言うとき**あなたはこのフィールド内のすべての値をしたいわけ最終的な結果に現れる? 'group by'操作でpax_numを持つようなもの? –

+0

はい、私はこの中にすべての値を書いておきたいと思います。私は結果がproductA-LAS-paxnum5-5訪問者であることを望みます。 productA-LAS-paxnum6-6の訪問者が現在productA-LAS-pax6-11visitorsです。それは最大paxnumをとります。私は2つのcustomDimensionsを持っているので、単にpax_numをグループに追加することはできません。これがあなたに合っているかどうか私に教えてください。 – Rachel

答えて

0

たdest +最大(pax_num)、DEST + pax_numのすべての組み合わせがない必要はありませんが、あなたはあなたによって、グループ内のフィールドpax_numが含まれている場合すでにそのように、あなたが必要なものを見つけるかもしれません:

select 
    date, 
    count(distinct(concat(FULLVISITORID,cast(visitID as string)))) as sessions, 
    product.v2ProductCategory category, 
    max(if(customDimensions.index=2, customDimensions.value, null)) as dest, 
    if(customDimensions.index=21, customDimensions.value,null) as pax_num, 
    eCommerceAction.action_type as act_type, 
    product.v2ProductName as product_name 
from `table` as t, 
unnest(hits) as hit, 
unnest(hit.customDimensions) customDimensions, 
unnest(hit.product) as product 
group by 
    date, 
    category, 
    act_type, 
    pax_num, 
    product_name 
having pax_num is not null 

あなたは一例としてpax_num値「paxnum_5」と「paxnum_6」を与えました。 group byオペレーションに値pax_numを挿入すると、countアグリゲーションは、値を保持するpax_numのレベルで発生します(すべてを前と同じようにmaxの値に混ぜてはいけません)。

はまた、(その定義は同じではありません)あなたはfullvisitoridsvisitidsの明確な組み合わせを数える場合は、実際のセッションではなく、訪問者の合計金額を計算していることに気づきます。

+0

こんにちは、私はそれを試しました。 having節にpax_numを追加すると、すべてのpax_numに対してnull値が返されます。句を持つことからpax_numを削除すると、destまたはpaxのいずれかを取得できるという結果が得られました。たとえば、次のようになります。Dest:LAS、Pax:nullまたはDest:NULL、Pax:2私はDest:LAS、Pax:2を同時に取得したい。 Pax属性はpaxのカウントまたは合計ではなく、記録する文字列の値です。 – Rachel

+0

この場合、私はあなたが必要としているものをかなり理解していないのではないかと心配しています。たぶんあなたの質問にあなたが持っているいくつかの入力と期待される出力があなたが必要とするより良い答えに私たちを助けるかもしれない例を挙げてください。 –

0

私は理解している場合fullvisitorIDは

SELECT 
    Date 
,concat(fullVisitorID,cast(visitID as string)) as visitorID 
    ,count(distinct(concat(FULLVISITORID,cast(visitID as string)))) as visitor 
, product.v2ProductCategory as product_category 

    ,max(if(customDimensions.index=2, customDimensions.value,null)) as dest 
    ,max((if(customDimensions.index=21, customDimensions.value,null))) as pax_num 
,eCommerceAction.action_type as Action_type 

,product.v2ProductName as product_name 
FROM `table` as t 
    CROSS JOIN UNNEST(hits) AS hit 
    CROSS JOIN UNNEST(hit.customDimensions) AS customDimensions 
    CROSS JOIN UNNEST(hit.product) AS product 

GROUP BY 
     Date 
     ,product.v2ProductCategory 
    ,eCommerceAction.action_type 
,product.v2ProductName 
,visitorID 
関連する問題