# 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:** [8월 14, 2015, 8:44오후 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:** 6

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [8월 25, 2023, 1:21오전 UTC](https://meta.discourse.org/t/badge-for-posts-with-likes-from-a-specific-group/276728/6 "2023-08-25T01:21:41Z")

</div>

모든 카테고리에 대해 동일한 쿼리를 사용하시려는 건가요?

```sql
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 (
        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 '<GROUP>' ) 
            )
    ) >= <MINIMUM LIKE COUNT>
    AND p.user_id >= 0
GROUP BY p.user_id
HAVING count(*) >= <POST COUNT THRESHOLD>

```

---

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