我有一个案例陈述,对下面的互动进行评分,我的问题与这一行有关: 当hits.eventInfo.eventAction CONTAINS“Basket Icon Click”然后5 else 0 end +
当使用值5,10,15运行时,它不会增加分数,如果我将值设置为1000,那么这确实会影响分数。谁能解释一下这里发生了什么?
select visitID, ROUND(SUM(Session_Score)/SUM(totals.hits),2) as Session_Score
from (
select *,
case when totals.pageviews > 2 then 5 else 0 end +
case when totals.pageviews > 5 then 10 else 0 end +
case when totals.pageviews > 10 then 20 else 0 end +
case when totals.transactions > 0 then 100 else 0 end +
case when hits.page.pagePath CONTAINS "Checkout" then 50 else 0 end +
case when hits.page.pagePath CONTAINS "SignIn" then 30 else 0 end +
case when hits.eventInfo.eventAction CONTAINS "Basket Icon Click" then 5 else 0 end +
case when geoNetwork.country = "United Kingdom" then 1 else 0 end +
case when hits.hour = 20 then 1 else 0 end +
case when hits.hour = 21 then 1 else 0 end +
case when hits.hour = 22 then 1 else 0
end as Session_Score
from [tbl]
) scored
GROUP by visitID
order by Session_Score desc
答案 0 :(得分:1)
我认为这是因为你正在使用ROUND(...)。如果你没有ROUND()Session_Score,它是否正确改变了?
另外,有关如何重写到standardSql的一些指导。这不是替代品,但您确实需要将CONTAINS "foo"
更改为LIKE "%foo%"
。如果你有任何重复的字段,你可能需要做一些相关的交叉连接(我不能从你的例子中说出来)。
#standardSQL
WITH
tbl AS (
SELECT
1 AS visitID,
10 AS pageviews,
1 AS hits,
"Checkout SignIn" AS pagePath,
"Basket Icon Click" AS eventAction)
SELECT
visitID,
ROUND(SUM(Session_Score)/SUM(hits), 2) AS Session_Score
FROM (
SELECT
*,
CASE
WHEN pageviews > 2 THEN 5
ELSE 0
END +
CASE
WHEN pageviews > 5 THEN 10
ELSE 0
END +
CASE
WHEN pageviews > 10 THEN 20
ELSE 0
END +
CASE
WHEN pagePath LIKE "%Checkout%" THEN 50
ELSE 0
END +
CASE
WHEN pagePath LIKE "%SignIn%" THEN 30
ELSE 0
END +
CASE
WHEN eventAction LIKE "%Basket Icon Click%" THEN 5
ELSE 0
END as Session_Score
FROM
tbl)
GROUP BY
visitID
ORDER BY
Session_score DESC