【发布时间】:2017-06-29 10:22:06
【问题描述】:
我在 Bigquery 有不同的查询,但每个月只需要运行一次(包含上个月的所有关闭数据)。 目前我在查询中手动更改日期,但我需要更改它并创建一个函数,为我提供过去的数据。
例如:我在 7 月 1 日或 2 日运行此查询,并且需要查询从 6 月 1 日到 30 日获取数据。 (查询是用标准 SQL 方言编写的)
谢谢。
代码:
SELECT
hits.contentGroup.contentgroup2 AS CampaignGrouping,
custd.value AS member_PK,
PARSE_TIMESTAMP('%Y%m%d',date) AS date,
'WebMobile' AS Canal,
'MX' AS country_id,
SUM(hits.contentGroup.contentGroupUniqueViews2) AS VistasUnicas
FROM
`bigquery-xxxx-xxxxx.111111.ga_sessions*`,
UNNEST(customdimensions) custd,
UNNEST(hits) AS hits
WHERE
1 = 1
AND PARSE_TIMESTAMP('%Y%m%d', REGEXP_EXTRACT(_table_suffix, r'.*_(.*)')) BETWEEN TIMESTAMP('2017-06-01') AND TIMESTAMP('2017-06-30')
AND custd.index=30
and hits.contentGroup.contentGroup2 <> '(not set)'
AND custd.value <> 'null'
AND hits.contentGroup.contentGroupUniqueViews2 IS NOT NULL
GROUP BY 1, 2, 3, 4, 5
【问题讨论】:
标签: mysql sql google-bigquery