我有一张有客户的表,我想找出客户在哪一个月遇到或超过了一定数量的请求。
该表有 customer_id 每个请求的时间戳。
我要查找的是客户满足或超过 10000 个请求的月份(或日期)。我试图得到一个运行总数,但这对我不起作用。我把它留在了代码中,以防有人知道我该怎么做。
我所拥有的是以下内容:
SELECT
customer_id
, DATE_TRUNC(CAST(TIMESTAMP_MILLIS(created_timestamp) AS DATE), MONTH) as cMonth
, COUNT(created_timestamp) as searchCount
-- , SUM(COUNT (DISTINCT(created_timestamp))) OVER (ROWS UNBOUNDED PRECEDING) as RunningTotal2
FROM customer_requests.history.all
GROUP BY distributor_id, cMonth
ORDER BY 2 ASC, 1 DESC;
我所追求的代表是这样的。
customer requests cMonth totalRequests
cust1 6000 2017-10-01 6000
cust1 4001 2017-11-01 10001
cust2 4000 2017-10-01 4000
cust2 4000 2017-11-01 8000
cust2 4000 2017-12-01 12000
cust2 3000 2017-12-01 3000
cust2 3000 2017-12-01 6000
cust2 3000 2017-12-01 9000
cust2 3000 2017-12-01 12000