在我的表trips
中,我有两列:created_at
和user_id
我的目标是通过postgres中的查询计算每月唯一user_id
秒。到目前为止,我写了这个 - 但它返回错误
SELECT user_id,
to_char(created_at, 'YYYY-MM') as t COUNT(*)
FROM (SELECT DISTINCT user_id
FROM trips) group by t;
我该如何更改此查询?
答案 0 :(得分:0)
查询比这简单得多:
SELECT to_char(created_at, 'YYYY-MM') as yyyymm, COUNT(DISTINCT user_id)
FROM trips
GROUP BY yyyymm
ORDER BY yyyymm;