Search for number of solved topics per user

Hi All,

I am looking to build a query in the data explorer - and being completely new to it, am not sure where to start!

I would like to run the following query:
Return the number of topics with a post marked as a solution by folk not in a given group, for a start and end date.

I couldn’t see any similar queries that do this, so my apologies if I missed it. All hints and tips gratefully received!

Cheers,

Lju

1 Like

Hello and welcome @lju :slight_smile:

This topic has a couple of examples in to get you started - How to get number of solutions per users using Data Explorer?

4 Likes

Hi @JammyDodger

Thanks for that - it was helpful, and I think I got my head around the various fields :slight_smile:

As a former data architect, I dream of having some sort of a data model to refer to, hint, hint

Cheers,

Lju

2 Likes

6 posts were split to a new topic: We should have a data model to make perusing the database easier

I think you should be able to do it with two if you use group_users. Maybe something like:

-- [params]
-- string :group_name = staff
-- date :date_from = 01/04/2022
-- date :date_to = 01/05/2022


SELECT
gu.group_id,
ua.user_id,
COUNT(1) AS solved_count
FROM user_actions ua
JOIN group_users gu on ua.user_id = gu.user_id
WHERE ua.action_type = 15
AND gu.group_id = (SELECT id FROM groups WHERE name = :group_name)
AND ua.created_at::date BETWEEN :date_from::date AND :date_to::date
GROUP BY gu.group_id, ua.user_id
ORDER BY solved_count DESC

(FYI group_name is case sensitive)


Update: Belatedly realised I added in a third when I made the group look-up a bit more user-friendly than using a straight group_id. But it could be done with two. :slightly_smiling_face:

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.