# Badge for posts with Likes from a specific group

**URL:** <https://meta.discourse.org/t/badge-for-posts-with-likes-from-a-specific-group/276728>\
**Category:** Data & reporting\
**Tags:** sql-triggered-badge\
**Created:** [August 14, 2015, 8:44pm UTC](https://meta.discourse.org/t/badge-for-posts-with-likes-from-a-specific-group/276728 "2015-08-14T20:44:45Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)\
**Post date:** [August 14, 2015, 8:44pm UTC](https://meta.discourse.org/t/badge-for-posts-with-likes-from-a-specific-group/276728/1 "2015-08-14T20:44:45Z")

</div>

As already mentioned [here](https://meta.discourse.org/t/what-is-this-bug-reporter-badge/17987/13):

Grant a badge to everyone having posted at least `<POST_COUNT>` posts in the category `<CATEGORY_NAME>` that have received at least `<LIKE_COUNT>` likes by users in the group `<TEAM_NAME>`. Similar to the bug reporter badge here, but can require more than one like.

```plaintext
SELECT p.user_id, min(p.created_at) granted_at, MIN(p.id) post_id
FROM badge_posts p
JOIN topics t ON t.id = p.topic_id
WHERE category_id = (
        SELECT id FROM categories WHERE name ilike '<CATEGORY_NAME>'
    ) AND (
        SELECT count(*)
        FROM post_actions pa
        WHERE pa.post_id = p.id
            AND post_action_type_id = (
                SELECT id FROM post_action_types WHERE name_key = 'like'
            ) AND pa.user_id IN (
                SELECT gu.user_id
                FROM group_users gu
                WHERE gu.group_id = ( SELECT id FROM groups WHERE name ilike '<TEAM_NAME>' ) 
            )
    ) >= <LIKE_COUNT>
    AND p.post_number = 1
    AND p.user_id >= 0
GROUP BY p.user_id
HAVING count(*) >= <POST_COUNT>

```

---

_[View the full topic](https://meta.discourse.org/t/badge-for-posts-with-likes-from-a-specific-group/276728)._
