查询是:
SELECT
user_id,
session_cnt,
NTILE(8) OVER (PARTITION BY user_id ORDER BY session_cnt DESC) ntile,
FROM (
SELECT
user_id,
COUNT(*) AS session_cnt,
FROM
[my_ds.my_table]
WHERE
event = 'pageview'
AND DATEDIFF(CURRENT_TIMESTAMP(), event_date) <= 30
GROUP BY
user_id
)
ORDER BY ntile desc, session_cnt desc
所有行的ntile值均为1。为什么会这样?
答案 0 :(得分:0)
您的子查询每个user_id返回一行! 您的外部选择尝试存储由user_id分区的所有行,但每个user_id只有一行,因此只生成一个存储桶