BigQuery& Firebase - 基于Key的Sum事件值

时间:2017-01-24 12:19:49

标签: firebase google-bigquery analytics firebase-analytics

在我的Android应用程序中,我正在记录用户选择的项目数量,如下所示

public static void trackItemsSelectedCount(Context context, int count) {
    Bundle bundle = new Bundle();
    bundle.putInt("count", count);
    getAnalytics(context).logEvent("items_selected", bundle);
}

在BigQuery中,我可以计算出事件items_selected的条目数量

SELECT event_dim.name as event,
COUNT(event_dim.name) as event_count
FROM TABLE_DATE_RANGE(package_ANDROID.app_events_intraday_, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP())
where event_dim.name contains 'items_selected'
GROUP BY event
ORDER BY event DESC LIMIT 1;

我希望获得event_dim.params.value.int_value的{​​{1}}和count

的和

到目前为止,我正在执行以下操作,但这可能不准确(因为event_dim.params.key没有出现在任何地方)。任何更精确的查询的想法将不胜感激:

event_dim.params.key

答案

SELECT event_dim.name as event,
COUNT(event_dim.name) as event_count ,
COUNT(event_dim.params.value.int_value) as value_count
FROM TABLE_DATE_RANGE(package_ANDROID.app_events_intraday_, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP())
where event_dim.name contains 'items_selected'
GROUP BY event
ORDER BY event DESC LIMIT 1;

1 个答案:

答案 0 :(得分:0)

SELECT 
    SUM((SELECT params.value.int_value FROM x.params WHERE params.key = 'count')) AS count 
FROM package_ANDROID.app_events_20170123, UNNEST(event_dim) AS x
WHERE x.name = 'items_selected'