【发布时间】:2020-10-12 21:43:25
【问题描述】:
您好,谁能帮我解决这个问题。我想做的是对我的会话ID进行排名,但它似乎不起作用,因为它只返回“1”。 第三行应该是 2,第 5 行应该有 2 排名,第 6 行应该有 3 排名等等。我尝试枚举会话。非常感谢你
WITH
hits AS (
SELECT
TIMESTAMP_SECONDS(visitstarttime) AS timestamp,
fullVisitorId,
CONCAT(fullvisitorId, CAST(visitStartTime AS STRING)) AS sessionId,
hits.page.pagePath,
hits.isEntrance,
hits.isInteraction,
hits.type,
hits.hitNumber,
MIN(hits.hitNumber) OVER (PARTITION BY fullVisitorId, visitStartTime) AS first_hit,
FROM `dl-training-bigquery.ND_177736451.ga_sessions_20191202` AS ga_table,
UNNEST(hits) AS hits
WHERE hits.type = 'PAGE'
)
SELECT
fullVisitorId,
sessionId,
pagePath,
timestamp,
MIN(timestamp) AS visit_time,
RANK() OVER(PARTITION BY CONCAT(fullvisitorId, "-", CAST(timestamp AS STRING)) ORDER BY sessionId ASC) AS Rank
FROM hits
WHERE type = 'PAGE'
GROUP BY 1,2,3,4
ORDER BY sessionId
【问题讨论】:
标签: sql datetime google-bigquery window-functions