在我们的数据库中,每个用户都有created_at
和cancelled_at
日期。如何计算用户活动天数的分布(具有cancelled_at
日期)。
答案 0 :(得分:1)
通过分发,我希望你能看到直方图。为此,您需要聚合:
select date_part('day', cancelled_at - created_at) as activedays, count(*)
from databasetable
group by date_part('day', cancelled_at - created_at)
order by activedays;
答案 1 :(得分:0)
SELECT *,DATE_PART('day', cancelled_at - created_at) as daysActive
FROM tableName
WHERE cancelled_at IS NOT NULL
答案 2 :(得分:0)
with cte as
(
SELECT DATE_PART ('day', cancelled_at - created_at) as daysactive FROM yourTable WHERE
cancelled_at
IS NOT NULL
)
select daysactive || ' day(s)' as days_active from cte