# Fetch solutions per user

**URL:** https://meta.discourse.org/t/fetch-solutions-per-user/141776
**Category:** Data & reporting
**Tags:** solved, sql-query
**Created:** [February 17, 2020, 7:50am UTC](https://meta.discourse.org/t/fetch-solutions-per-user/141776 "2020-02-17T07:50:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Konrad\_Sopala](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/konrad_sopala/32/167014_2.png) [@Konrad\_Sopala](https://meta.discourse.org/u/Konrad_Sopala)
#### Post date: [February 17, 2020, 7:50am UTC](https://meta.discourse.org/t/fetch-solutions-per-user/141776/1 "2020-02-17T07:50:26Z")

</div>

Hey there!

Searched through the whole forum and did a bit of development myself but cannot create a query to fetch all users with the number of solutions given by them in a certain period of time. Thanks for help!

---

<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: [February 19, 2020, 2:26am UTC](https://meta.discourse.org/t/fetch-solutions-per-user/141776/2 "2020-02-19T02:26:30Z")

</div>

You can get solved topics from the `user_actions` table. Solved topics in that table have their `action_type` set to 15.

Here’s a general query for getting solved counts for users within a given time period. You’ll need to set the `start_date` and `end_date` parameters before running the query. Those parameters should be in the form of `yyyy-mm--dd`. For example `2020-02-18`.

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

SELECT
user_id,
COUNT(user_id) 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

```
