我正在学习SQL,所以我不确定我的问题。我正在运行以下查询:
SELECT count(key), FORMAT_DATE("%Y-%m", DATE(min(created_date))) as First_Month
FROM `xxxxxxxx.xxxxxxx_xxxxx.xxxxxxxx` as table
GROUP BY First_Month
ORDER BY First_Month
大查询会返回此错误:
Error: Column First_Month contains an aggregation function, which is not allowed in GROUP BY at [3:10]
基本上我有一张包含帐户和付款清单的表格。我想要做的是计算第一个月的帐户数量。我认为我们称之为队列分析...但我不确定。
我觉得除了我的问题之外还有更复杂的事情,但我无法表达......
答案 0 :(得分:2)
使用子查询。大概你打算这样的事情:
SELECT count(*), FORMAT_DATE("%Y-%m", DATE(min_created_date)) as First_Month
FROM (SELECT t.key, min(created_date) as min_created_date
FROM `xxxxxxxx.xxxxxxx_xxxxx.xxxxxxxx` t
GROUP BY t.key
) t
GROUP BY First_Month
ORDER BY First_Month
LIMIT 1000;
如果您期待超过1000个月的历史,那么您有很多历史。