使用bigquery选择多个命中范围的自定义维度

时间:2016-09-10 21:56:38

标签: google-bigquery

我正在尝试获取在特定日期至少进行一次购买的客户列表。只选择date和customer_id时,下面的bigquery可以正常工作。但是,尽管我知道数据存在,但city始终返回null。

在选择多个命中范围的自定义维度时,是否需要使用其他方法?

SELECT date
,CASE WHEN hits.customdimensions.index = 5 
 THEN hits.customdimensions.value END as customer_id
,CASE WHEN hits.customdimensions.index = 50 
 THEN hits.customdimensions.value END as city
FROM (TABLE_DATE_RANGE([16475821.ga_sessions_],
      TIMESTAMP('2016-09-01'), TIMESTAMP('2016-09-07'))
GROUP BY 1, 2, 3
HAVING sum(case when hits.eventInfo.eventAction = 'purchase' then 1 end) > 0 
       and customer_id is not null

1 个答案:

答案 0 :(得分:1)

没有任何数据可以再次测试,但视觉评估 - 下面应该对你有用

SELECT 
  date,
  MAX(CASE WHEN hits.customdimensions.index = 5 
           THEN hits.customdimensions.value END) WITHIN RECORD AS customer_id
  MAX(CASE WHEN hits.customdimensions.index = 50 
           THEN hits.customdimensions.value END) WITHIN RECORD AS city
  SUM(CASE WHEN hits.eventInfo.eventAction = 'purchase' 
           THEN 1 END) WITHIN RECORD AS purchases_count
FROM (TABLE_DATE_RANGE([16475821.ga_sessions_],
      TIMESTAMP('2016-09-01'), TIMESTAMP('2016-09-07')))
HAVING purchases_count > 0
AND NOT customer_id IS NULL