SELECT
webPage,
webPage_2,
webPage_3,
webPage_4,
count(*) journeys
FROM(
SELECT webPage,
NEXT(webPage, 1, true) OVER(PARTITION BY ecid, session.num ORDER BY timestamp ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING).value AS webPage_2,
NEXT(webPage, 2, true) OVER(PARTITION BY ecid, session.num ORDER BY timestamp ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING).value AS webPage_3,
NEXT(webPage, 3, true) OVER(PARTITION BY ecid, session.num ORDER BY timestamp ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING).value AS webPage_4,
session.depth AS SessionPageDepth
FROM (
SELECT a._adobedemoamericas275.identification.core.ecid as ecid,
a.timestamp, web.webPageDetails.name as webPage,
SESS_TIMEOUT(timestamp, 60 * 30) OVER (PARTITION BY a._adobedemoamericas275.identification.core.ecid ORDER BY timestamp ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS session
FROM demo_system_event_dataset_for_website_global_v1_1 a
WHERE a._adobedemoamericas275.identification.core.ecid IN (
SELECT b._adobedemoamericas275.identification.core.ecid
FROM demo_system_event_dataset_for_website_global_v1_1 b
WHERE web.webPageDetails.name = 'Home'
and b._adobedemoamericas275.identification.core.ecid IS NOT NULL
)
)
)
WHERE SessionPageDepth=1 and webpage_3 = 'Home'
GROUP BY webPage, webPage_2, webPage_3, webPage_4
ORDER BY journeys DESC
LIMIT 10;