I am trying to calculate the percentatge of sessions per month based on some categories the users have visited on the website on Google BigQuery.
The query is the following one. It seems it has no error apparently, but when I run it, it says: 'Scalar subquery produced more than one element'.
Do you know why this is happening? Thanks!
WITH cte AS (
SELECT
partition_date as session_date,
EXTRACT(MONTH FROM CAST(partition_date AS date)) AS month,
COUNT(CONCAT(CAST(fullVisitorId as string),
CAST(visitId as string)
)) AS sessions,
h.page.pagePath AS page_path,
CASE WHEN h.page.pagePath LIKE '%/account/profile/%' THEN 'My Profile'
WHEN h.page.pagePath LIKE '%/myaccount/orders%' THEN 'My Orders'
WHEN h.page.pagePath LIKE '%/myaccount/wishlist' THEN 'My Wishlist'
ELSE NULL END as categories,
(SELECT count(CONCAT(CAST(fullVisitorId as string),
CAST(visitId as string)
)) over (partition by EXTRACT(MONTH FROM CAST(partition_date AS date)))
FROM `*.BO_*.ga_sessions`,
UNNEST(hits) AS h
WHERE partition_date BETWEEN '2022-07-31' AND '2022-08-01') as total_sessions
FROM
`*.BO_*.ga_sessions`, UNNEST(hits) AS h
WHERE partition_date BETWEEN '2022-07-31' AND '2022-08-01'
GROUP BY 1, 5
)
SELECT
month,
categories,
total_sessions,
sessions/total_sessions,
FROM cte
WHERE categories IS NOT NULL
GROUP BY 1, 2, 3, 4