我正在尝试计算这2页的唯一网页浏览量。
我对case函数有这个查询但是当我为每个页面参数分别运行以下查询时,我得到的结果与运行它时的结果不同。但综合结果不准确。有人可以告诉我这里我做错了吗?
SELECT
COUNT(DISTINCT (CASE WHEN hits.type = "PAGE" THEN CONCAT(fullvisitorid,
STRING(visitid), hits.page.pagepath) END)) AS UniquePageViews,
CASE WHEN (REGEXP_MATCH (hits.page.pagePath, '(.*account=true)')) THEN "Accounts"
WHEN (REGEXP_MATCH (hits.page.pagePath, '(.*subscribed)')) THEN "Signups" ELSE "Others" END AS Goals
FROM
[mydata.ga_sessions_20150506]
GROUP BY
Goals
答案 0 :(得分:0)
问题可能是同一"account=true"
字符串"subscribed"
和pagePath
都存在的情况,因此当您尝试计算它们时,只考虑一个字符串。
解决问题的一种方法是改变匹配条件,例如:
SELECT
EXACT_COUNT_DISTINCT(CASE WHEN hits.type = "PAGE" THEN CONCAT(fullvisitorid,
STRING(visitid), hits.page.pagepath) END) AS UniquePageViews,
CASE WHEN (REGEXP_MATCH (hits.page.pagePath, '(account=true)') AND NOT REGEXP_MATCH (hits.page.pagePath, '(subscribed)')) THEN "Accounts"
WHEN (REGEXP_MATCH (hits.page.pagePath, '(subscribed)') AND NOT REGEXP_MATCH (hits.page.pagePath, '(account=true)')) THEN "Signups"
WHEN (REGEXP_MATCH (hits.page.pagePath, '(subscribed)') AND REGEXP_MATCH (hits.page.pagePath, '(account=true)')) THEN "Both"
ELSE "Others" END AS Goals
FROM
[mydata.ga_sessions_20150506]
GROUP BY
Goals
我强制条件仅匹配"account=true"
而不是"subscribed"
。
举个例子,这是我在ga_sessions数据集上测试的内容:
SELECT
exact_count_distinct(CASE WHEN hits.type = "PAGE" THEN CONCAT(fullvisitorid, STRING(visitid), hits.page.pagepath) END) AS UniquePageViews,
CASE WHEN (REGEXP_MATCH (hits.page.pagePath, '(colcci)') AND NOT REGEXP_MATCH (hits.page.pagePath, '(lacoste)')) THEN "colcci"
WHEN (REGEXP_MATCH (hits.page.pagePath, '(lacoste)') AND NOT REGEXP_MATCH (hits.page.pagePath, '(colcci)')) THEN "lacoste"
WHEN (REGEXP_MATCH (hits.page.pagePath, '(lacoste)') AND REGEXP_MATCH (hits.page.pagePath, '(colcci)')) THEN 'both'
ELSE "Others" END AS Goals
FROM [40663402.ga_sessions_20150506]
GROUP BY
Goals
希望这会有所帮助。有任何问题请告诉我们,