你好!
我希望了解在给定类别中,有多少比例的新话题在第一周内未收到回复,以及有多少比例在第一周内得到了解决。以下是我的查询:
-- [params]
-- string :start_date = 2021-10-06
-- string :end_date = 2021-10-12
WITH solved_topics as
(SELECT
t.created_at::DATE,
t.id,
count(distinct case when u.action_type=15 and u.created_at < (t.created_at + INTERVAL '1 week') and u.target_topic_id=t.id then 1 ELSE NULL END) as solves,
count(distinct case when p.created_at < (t.created_at + INTERVAL '1 week') and p.topic_id=t.id and p.post_number>1 then 1 ELSE NULL END) as responses
from topics t
join user_actions as u
on u.target_topic_id = t.id
join posts as p
on p.topic_id = t.id
where t.created_at BETWEEN :start_date AND :end_date
AND t.user_id > 0
AND p.deleted_at is NULL
AND t.category_id is NOT NULL
group by t.created_at::DATE, t.id)
SELECT
st.created_at as date,
count(distinct st.id) as "Number of New Topics",
sum(st.solves)::INT as "# Solved within a week",
round(sum(st.solves)/count(distinct st.id), 2) as "% Solved",
(count(distinct st.id) - sum(st.responses))::INT as "Topics with No Response in First Week",
round((count(distinct st.id) - sum(st.responses))/count(distinct st.id), 2) as "% with No Response in First Week"
from solved_topics as st
group by date
order by date asc
我相信肯定有更优雅的实现方式,但我已经抽查了多个日期,这些数字与我查看单个话题时看到的情况一致。
我假设,对于过去一周内的任何一天,在 /admin/reports/topics_with_no_response 处找到的报告应显示相同数量的无回复话题。在大多数情况下确实如此;但在其他情况下,它显示的无回复话题数量比我查询得到的要多。
有什么想法可以解释这一现象吗?是否有一种方法可以查看驱动“无回复话题”报告的查询,以便我进行对比分析?
提前感谢!