Data Explorer Queries for Solved Statistics

Here are a few Data Explorer queries that you can use for getting information about Solutions:

To list each individual “solved” event:

SELECT acting_user_id, 
       target_topic_id AS topic_id, 
FROM user_actions
WHERE action_type=15
ORDER BY created_at DESC

To produce a list with stats per-user: (with variable for time interval, defaults to 1 year):

-- [params]
-- string :interval = 1 year

SELECT  ua.acting_user_id, 
        COUNT(CASE t.user_id WHEN ua.acting_user_id THEN 1 ELSE NULL END) as is_op, 
        COUNT(CASE t.user_id WHEN ua.acting_user_id THEN NULL ELSE 1 END) as not_op,
        COUNT(*) as total
FROM user_actions ua
LEFT JOIN topics t ON target_topic_id =
WHERE action_type=15
AND ua.created_at >= CURRENT_DATE - INTERVAL :interval
GROUP BY ua.acting_user_id

To look up who has marked a particular topic as Solved:

-- [params]
-- topic_id :topic_id 

SELECT target_topic_id, 
FROM user_actions
WHERE target_topic_id = :topic_id
AND action_type = 15
ORDER BY created_at DESC

:warning: DRAFT

This query would give solved/unsolved, the first reply | first replier | hours to first reply, as well as the solution post | solver | hours to solution (with category and ‘topic created since’ parameters).

If anyone wants to sanity check it before I add it to the OP that would be great. :slight_smile: :+1:

-- [params]
-- int :category_id = 6
-- date :since = 2013-01-01

WITH solved_topics AS (

SELECT ua.target_topic_id AS topic_id,
       ua.target_post_id AS post_id,
FROM user_actions ua
JOIN posts p on = ua.target_post_id
WHERE action_type = 15


first_reply AS (
    SELECT p.topic_id, 
           MIN(id) AS post_id
    FROM posts p
    WHERE p.deleted_at ISNULL
    AND p.post_type = 1
    AND p.post_number > 1
    GROUP BY p.topic_id

SELECT CASE WHEN st.topic_id IS NOT NULL THEN 'Solved' ELSE 'Unsolved' END AS "Solved?", as topic_id,
       t.user_id AS question_user_id,
       t.created_at::date AS "Topic Posted On:",
       p.user_id AS first_reply_user_id,
       COALESCE(fr.post_id, 0) AS first_reply_post_id,
       COALESCE(CEIL(extract(epoch FROM (p.created_at - t.created_at))/3600.00),0) AS "Time to First Reply (hrs)",
       st.user_id AS solved_by_user_id,
       COALESCE(st.post_id,0) AS solution_post_id,
       COALESCE(CEIL(extract(epoch FROM (st.created_at - t.created_at))/3600.00),0) AS "Time to Solution (hrs)"
FROM topics t
LEFT JOIN solved_topics st ON = st.topic_id
LEFT JOIN first_reply fr ON fr.topic_id =
LEFT JOIN posts p ON = fr.post_id
WHERE t.category_id = :category_id
AND t.created_at >= :since
AND t.deleted_at ISNULL
AND t.visible = TRUE
ORDER BY t.created_at