# Badge query request: Received X likes in topic containing specific tag

**URL:** https://meta.discourse.org/t/badge-query-request-received-x-likes-in-topic-containing-specific-tag/27901
**Category:** Data & reporting
**Tags:** sql-triggered-badge
**Created:** [2015年四月24日 11:35 UTC](https://meta.discourse.org/t/badge-query-request-received-x-likes-in-topic-containing-specific-tag/27901 "2015-04-24T11:35:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![erlend\_sh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erlend_sh/32/119475_2.png) [@erlend\_sh](https://meta.discourse.org/u/erlend_sh)
#### Post date: [2015年四月24日 11:35 UTC](https://meta.discourse.org/t/badge-query-request-received-x-likes-in-topic-containing-specific-tag/27901/1 "2015-04-24T11:35:14Z")

</div>

Continuing the discussion from [What cool badge queries have you come up with?](https://meta.discourse.org/t/what-cool-badge-queries-have-you-come-up-with/18978).

Our forum has “Monthly Screenshots” threads. I’d like to reward the people who participate in these with a badge. I don’t know if there’s an easy way to tell if a post contains an image, but if so then that would be a welcome addition to the query.

The simplest query I can think of would be to award this badge to anyone who receives \>1 like on a post in a topic tagged `monthly-screenshots`.

Why \>1 likes? Because many people also reply to the image-posters, but these commenters very rarely receive more than 1 like (usually as a “thanks for the compliment” from an image-poster), so it’s _accurate enough_ for my needs.

---

<div class="post-metadata">

### Author: ![elberet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elberet/32/122404_2.png) [@elberet](https://meta.discourse.org/u/elberet)
#### Post date: [2015年四月24日 15:08 UTC](https://meta.discourse.org/t/badge-query-request-received-x-likes-in-topic-containing-specific-tag/27901/2 "2015-04-24T15:08:15Z")

</div>

```sql
select p.id, p.user_id, count(u.id)
from posts p
  left join post_uploads pu on p.id = pu.post_id
  left join uploads u on pu.upload_id = u.id 
where u.original_filename similar to '%.(jpg|png|)'
group by p.id, p.user_id
  having count(u.id) > 1

```

This finds all posts with at least two uploads that are images (end in either `.jpg` or `.png`).

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2021年六月11日 04:13 UTC](https://meta.discourse.org/t/badge-query-request-received-x-likes-in-topic-containing-specific-tag/27901/4 "2021-06-11T04:13:01Z")

</div>


