在bigquery中显示上个月的数据

时间:2016-02-24 02:27:16

标签: sql google-bigquery

如何从Google大查询中过滤上个月的数据(例如:1月1日 - 1月31日)

select count(distinct hits.customDimensions.value,20000000) as TotalUniqueUsers, 
       count(distinct IF(visitnumber=1, hits.customDimensions.value, NULL),20000000) as TotalNewUsers
from TABLE_DATE_RANGE([90461009.ga_sessions_],
                      DATE_ADD(CURRENT_TIMESTAMP(), -2, 'MONTH'), DATE_ADD(CURRENT_TIMESTAMP(), -1, 'MONTH')
                     )
where hits.customDimensions.index=4

我正在尝试类似上面的查询。请有人帮忙吗

谢谢!

1 个答案:

答案 0 :(得分:2)

尝试以下

SELECT 
  COUNT(DISTINCT hits.customDimensions.value,20000000) AS TotalUniqueUsers, 
  COUNT(DISTINCT IF(visitnumber=1, hits.customDimensions.value, NULL),20000000) AS TotalNewUsers
FROM TABLE_QUERY([90461009],
  "REGEXP_MATCH(table_id, 'ga_sessions_' + REPLACE(LEFT(STRING(DATE_ADD(CURRENT_TIMESTAMP(), -1, 'MONTH')), 7), '-', ''))")
WHERE hits.customDimensions.index=4