# Top 50 likers

**URL:** https://meta.discourse.org/t/top-50-likers/275116
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [February 12, 2018, 1:26pm UTC](https://meta.discourse.org/t/top-50-likers/275116 "2018-02-12T13:26: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: [February 12, 2018, 1:26pm UTC](https://meta.discourse.org/t/top-50-likers/275116/1 "2018-02-12T13:26:00Z")

</div>

### Top 50 likers

Returns the top 50 likers for a given monthly period. Results are ordered by like\_count. It accepts a ‘months\_ago’ parameter and defaults to 0 to give results for the current 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 like_count
FROM user_actions ua
INNER JOIN query_period qp
ON ua.created_at >= qp.period_start
AND ua.created_at <= qp.period_end
WHERE ua.action_type = 1
GROUP BY ua.user_id
ORDER BY like_count DESC
LIMIT 50

```
