데이터 탐색기 쿼리를 작성하려고 하는데, 다음 조건을 만족하는 토픽 목록을 반환해야 합니다:
- 토픽이 미해결 상태여야 합니다.
- 쿼리 실행 시점 기준 7일 이상 지난 토픽이어야 합니다.
데이터 탐색기 쿼리를 작성하려고 하는데, 다음 조건을 만족하는 토픽 목록을 반환해야 합니다:
결국 문제를 해결했습니다! 다른 분들도 이 방법을 찾고 계실 수 있으니 공유합니다. 이 쿼리는 7일에서 40일 사이 생성된 미해결 주제(토픽)를 조회하는 것입니다.
WITH solved_topics AS (
SELECT ua.target_topic_id AS topic_id,
ua.user_id,
ua.target_post_id AS post_id,
p.created_at
FROM user_actions ua
JOIN posts p on p.id = ua.target_post_id
WHERE action_type = 15
)
SELECT t.id as topic_id,
t.user_id AS question_user_id,
t.created_at::date AS "Topic Posted On:",
t.views
FROM topics t
LEFT JOIN solved_topics st ON t.id = st.topic_id
WHERE t.category_id = 37
AND t.created_at BETWEEN current_date - 40 AND current_date -7
AND t.deleted_at ISNULL
AND t.visible = TRUE
AND st.topic_id IS NULL
ORDER BY t.created_at
해결하셨다니 다행입니다. ![]()
숫자가 단 두 개라면 크게 유용하지 않을 수 있지만, 혹시 모를 경우를 대비해 Data Explorer 쿼리에 동적 파라미터를 추가할 수 있습니다. 이렇게 하면 쿼리를 직접 수정하는 대신 입력값으로 범위를 쉽게 선택할 수 있습니다: https://meta.discourse.org/t/discourse-data-explorer/32566#declaring-parameters-in-your-query-8