创建将参数显示为列的查询 - BigQuery
Posted
技术标签:
【中文标题】创建将参数显示为列的查询 - BigQuery【英文标题】:Creating a query that shows parameters as columns - BigQuery 【发布时间】:2019-01-28 15:39:17 【问题描述】:我正在使用 Firebase 和 BigQuery。 我试图做的是创建查询,显示平均数量的“订单”和每个“级别”的“软货币”,但我不知道该怎么做。
这是我数据库中示例事件的简化 JSON 文件。每次玩家达到下一个级别时都会发送此类事件。
[
"event_name": "LevelUp",
"event_params": [
"key": "Level",
"value":
"string_value": null,
"int_value": "12"
,
"key": "SoftCurrrency",
"value":
"string_value": null,
"int_value": "623"
,
"key": "Orders",
"value":
"string_value": null,
"int_value": "24"
]
]
【问题讨论】:
您必须获取所有数据并通过代码进行查询/过滤 【参考方案1】:我就是这样做的:
SELECT ANY_VALUE(Level) as Lvl, FLOOR(AVG(SoftCurrency)) as average_Coins, FLOOR(AVG(Orders)) as average_Orders
FROM (
SELECT MAX(if(param.key = "SoftCurrency", param.value.int_value, NULL)) AS SoftCurrency,
MAX(if(param.key = "Level", param.value.int_value, NULL)) AS Level,
MAX(if(param.key = "Orders", param.value.int_value, NULL)) AS Orders
FROM (
SELECT user_pseudo_id, event_timestamp, param
FROM `analytics`,
UNNEST(event_params) AS param
WHERE event_name = "LevelUp"
AND (param.key = "SoftCurrency" OR param.key = "Level" OR param.key = "Orders")
)
GROUP BY user_pseudo_id, event_timestamp
)
GROUP BY Level
ORDER BY Lvl
【讨论】:
以上是关于创建将参数显示为列的查询 - BigQuery的主要内容,如果未能解决你的问题,请参考以下文章