# Solved count by members (monthly)

**URL:** https://meta.discourse.org/t/solved-count-by-members-monthly/275111
**Category:** Data & reporting
**Tags:** solved, sql-query
**Created:** [February 12, 2018, 11:36am UTC](https://meta.discourse.org/t/solved-count-by-members-monthly/275111 "2018-02-12T11:36:00Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [February 12, 2018, 11:36am UTC](https://meta.discourse.org/t/solved-count-by-members-monthly/275111/1 "2018-02-12T11:36:00Z")

</div>

### Solved count by members (monthly)

Count of topics solved by regular members (defaults to last month)

```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
ua.user_id,
count(1) AS solved_count
FROM user_actions ua
INNER JOIN query_period qp
ON ua.created_at >= qp.period_start
AND ua.created_at <= qp.period_end
INNER JOIN users u
ON u.id = ua.user_id
WHERE ua.action_type = 15
AND u.admin = 'f'
AND u.moderator = 'f'
GROUP BY ua.user_id
ORDER BY solved_count DESC

```
