# 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:** 14

<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:** [August 25, 2023, 6:40am UTC](https://meta.discourse.org/t/badge-for-posts-with-likes-from-a-specific-group/276728/14 "2023-08-25T06:40:48Z")

</div>

I did this to get necessary schema tables for `posts`, `posts_actions`, `group_users` and `groups`

```sql
SELECT column_name, data_type, character_maximum_length
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE table_name = '<TABLE NAME>';

```

Then used this to get all the group IDs:

```sql
SELECT name, id FROM groups ORDER BY name

```

So then I included all the schema tables needed and instructed Lola, er GPTbot to use actual `post_action_code` id and the `group_id` code. Then after some arguing back and forth and making some corrections. We came up with this. Again, seems to work in [Data Explorer](https://meta.discourse.org/t/32566?silent=true), but I still cannot get anything out of it in the Badge Previewer.

```plaintext
G = group_id
X = minimum number of likes
Y = minimum number of posts

```

```sql
SELECT pa.user_id, MIN(pa.post_id) as post_id, COUNT(pa.post_id) as post_count, COUNT(pa.id) as like_count, MAX(pa.created_at) as granted_at
FROM post_actions pa
JOIN group_users gu ON gu.user_id = pa.user_id
WHERE gu.group_id = G AND pa.post_action_type_id = 2
GROUP BY pa.user_id
HAVING COUNT(pa.post_id) >= Y AND COUNT(pa.id) >= X

```

yes I named GP4bot Lola

---

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