Postgresql Postgres-错误:分组依据位置中不允许使用聚合函数:305

Postgresql Postgres-错误:分组依据位置中不允许使用聚合函数:305,postgresql,Postgresql,对潜望镜提供的查询有点小问题。你能帮我指出正确的方向吗 错误为-错误:分组依据位置305中不允许使用聚合函数 with monthly_activity as ( select distinct date_trunc('month', created_at) as month, user_id from oauth_refresh_tokens ), first_activity as ( select user_id, date(min(created_at))

对潜望镜提供的查询有点小问题。你能帮我指出正确的方向吗

错误为-错误:分组依据位置305中不允许使用聚合函数

with monthly_activity as (
  select distinct
    date_trunc('month', created_at) as month,
    user_id
  from oauth_refresh_tokens
), 
first_activity as (
  select user_id, date(min(created_at)) as month
  from oauth_refresh_tokens
  group by 2
)
select
  this_month.month,
  count(distinct user_id)
from monthly_activity this_month
left join monthly_activity last_month
  on this_month.user_id = last_month.user_id
  and this_month.month = last_month.month + interval '1 month'
join first_activity
  on this_month.user_id = first_activity.user_id
  and first_activity.month != this_month.month
where last_month.user_id is null
group by 1

您希望在第二个CTE中按用户id分组。谢谢!我必须更新一些其他东西,但它成功了。在我的情况下,用
按真分组
代替
按1分组
它。您希望在第二个CTE中使用
按用户id分组
。谢谢!我不得不更新一些其他的东西,但还是成功了。在我的例子中,
groupbytrue
取代了
groupby1
it。