# New user of the month, is it working?

**URL:** <https://meta.discourse.org/t/new-user-of-the-month-is-it-working/78270>\
**Category:** Feature\
**Created:** [January 17, 2018, 2:28pm UTC](https://meta.discourse.org/t/new-user-of-the-month-is-it-working/78270 "2018-01-17T14:28:48Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)\
**Post date:** [January 18, 2018, 10:52am UTC](https://meta.discourse.org/t/new-user-of-the-month-is-it-working/78270/14 "2018-01-18T10:52:52Z")

</div>

I’m thinking this query might be better : just counting the ❤s received

```sql
SELECT u.id,
  SUM(CASE
      WHEN liked_by.admin THEN 3.0
      WHEN liked_by.moderator THEN 3.0
      WHEN liked_by.trust_level = 4 THEN 2.0
      WHEN liked_by.trust_level = 3 THEN 1.5
      WHEN liked_by.trust_level = 2 THEN 1.0
      WHEN liked_by.trust_level = 1 THEN 0.25
      WHEN liked_by.trust_level = 0 THEN 0.1
      ELSE 1.0
      END) AS score
FROM users AS u
INNER JOIN user_stats AS us ON u.id = us.user_id
LEFT OUTER JOIN posts AS p ON p.user_id = u.id
LEFT OUTER JOIN post_actions AS pa ON pa.post_id = p.id AND pa.post_action_type_id = #{PostActionType.types[:like]}
LEFT OUTER JOIN users AS liked_by ON liked_by.id = pa.user_id
LEFT OUTER JOIN topics AS t ON t.id = p.topic_id
WHERE u.active
  AND u.id > 0
  AND liked_by.id > 0
  AND NOT u.staged
  AND NOT u.admin
  AND NOT u.moderator
  AND t.archetype <> '#{Archetype.private_message}'
  AND u.created_at >= CURRENT_TIMESTAMP - '1 month'::INTERVAL                                                                                                    
  AND u.id NOT IN (#{current_owners.join(',')})
GROUP BY u.id
HAVING COUNT(DISTINCT p.id) > 1
   AND COUNT(DISTINCT p.topic_id) > 1
   AND COUNT(pa.id) > 1
ORDER BY score DESC 
LIMIT #{MAX_AWARDED}

```

---

_[View the full topic](https://meta.discourse.org/t/new-user-of-the-month-is-it-working/78270)._
