# Topics solved by regular users

**URL:** https://meta.discourse.org/t/topics-solved-by-regular-users/275120
**Category:** Data & reporting
**Tags:** solved, sql-query
**Created:** [2월 12, 2018, 3:15오후 UTC](https://meta.discourse.org/t/topics-solved-by-regular-users/275120 "2018-02-12T15:15:00Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [2월 12, 2018, 3:15오후 UTC](https://meta.discourse.org/t/topics-solved-by-regular-users/275120/1 "2018-02-12T15:15:00Z")

</div>

### Topics solved by regular users

(There is probably a way to combine this query with the staff query.)

The number of topics solved by staff for a given time period, broken down by categories. The categories array can be altered by editing this line: `WHERE t.category_id = ANY ('{46,25,43,40,44,35,22,7,20,17,6,12}'::int[])`. It is possible to alter the query so that it returns results for all categories, or so that the categories array is supplied as a string parameter in the form `{1, 2, 3}`.

```sql
-- [params]
-- int :months_ago = 1

WITH query_period AS (
SELECT
date_trunc('month', CURRENT_DATE) - INTERVAL ':months_ago months' as period_start,
date_trunc('month', CURRENT_DATE) - INTERVAL ':months_ago months' + INTERVAL '1 month' - INTERVAL '1 second' as period_end
)

SELECT
t.category_id,
COUNT(1) AS solved_count
FROM user_actions ua
JOIN topics t
ON t.id = ua.target_topic_id
JOIN query_period qp
ON ua.created_at >= qp.period_start
AND ua.created_at <= qp.period_end
JOIN users u
ON u.id = ua.user_id
WHERE t.category_id = ANY ('{46,25,43,40,44,35,22,7,20,17,6,12}'::int[])
AND ua.action_type = 15
AND (u.admin = 'f' AND u.moderator = 'f')
GROUP BY t.category_id
ORDER BY solved_count DESC

```
