How to get number of solutions per users using Data Explorer?

Having in mind that we have Discourse Solved plugin installed as well as the Data Explorer plugin, what would be the query to get the number of solutions per user?

1 Like

When a user solves a topic, an entry is added to the user_actions table with its action_type set to 15.

The following query should give you what you are looking for:

SELECT
user_id,
COUNT(1) AS solved_count
FROM user_actions
WHERE action_type = 15
GROUP BY user_id
ORDER BY solved_count DESC
9 Likes

That works! Thanks a lot!

Hey there!

Got one more question regarding that. Does it count all the answers from public posts as well as those that the person marked as solution when exchanging private messages with someone? Thanks for help!

You can’t mark PMs as solved. It’s a per category setting.

2 Likes

One of the replies in private messaging thread marked as a solution. Does that also counts for person’s solutions count?

If the allow solved on all topics site setting is enabled, private message posts can be marked as solutions. If a private message post is marked as a solution, it will be included in the solution counts that are returned by the query that I posted.

3 Likes

Thanks a lot Simon for that knowledge!

As an addition to Simon’s query above, we use this version to view number of solutions per user for a specific date range (using yyyy-mm-dd date format):

--[params]
-- date :start_date
-- date :end_date

SELECT
user_id,
COUNT(1) AS solved_count
FROM user_actions
WHERE created_at::date BETWEEN :start_date AND :end_date
AND action_type = 15
GROUP BY user_id
ORDER BY solved_count DESC

It’s handy being able to see how this changes from month to month.

5 Likes

Thanks Ben for sharing that!

1 Like

Thanks everyone for sharing those queries!

I am setting up my discourse forum and I was wondering how to get the average time_to_resolution of the whole forum, much like the average_time-for_first_response.

Do you think it makes sense from a community perspective to have such information? If yes, I am not sure how to form that query. Any ideas?

Thanks!