‘응답 없는 주제’ 뒤의 쿼리 재현하기

안녕하세요!

특정 카테고리에서 첫 주에 답변을 받지 못한 새 토픽의 비율과 첫 주에 해결된 비율이 각각 얼마인지 파악하고 싶습니다. 제 쿼리는 다음과 같습니다:

-- [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

더 깔끔한 방법이 있을 것이라 생각합니다만, 여러 날짜를 직접 확인해 본 결과 제 쿼리의 숫자들은 개별 토픽을 직접 살펴볼 때 보는 내용과 일치합니다.

지난 1주일 이내의 어떤 날짜에 대해든, /admin/reports/topics_with_no_response에서 확인하는 리포트는 제 쿼리와 동일한 ‘첫 주에 답변이 없는 토픽’ 수를 보여줄 것이라 가정했습니다. 대부분의 경우 그렇게 나오지만, 다른 경우에는 제 쿼리보다 더 많은 '답변 없는 토픽’을 표시합니다.

이런 현상이 발생하는 이유가 무엇일까요? ‘답변 없는 토픽’ 리포트를 구동하는 쿼리를 확인하여 비교해 볼 수 있는 방법이 있을까요?

미리 감사드립니다!

응답이 없는 보고서 주제들을 주제 목록 분석 결과와 비교해 보니, 보고서에 표시된 숫자가 더 큰 것을 확인했습니다. 그리고 원글 작성자만 답글을 단 주제들도 '응답 없음’으로 집계된다는 결론을 내렸습니다.

질문자님이 주목하신 차이점의 원인이 정확히 이 때문이라고 단정할 수는 없습니다. 질문자님의 쿼리는 현재 수치가 아닌 ‘1주 후’ 수치만 반환하기 때문에 제가 직접 확인해 볼 수 없었기 때문입니다. 또한, 저는 SQL에 그렇게 능숙하지도 않습니다.