# 배지 쿼리에 카운터 매개변수를 추가하는 방법?

**URL:** <https://meta.discourse.org/t/how-to-add-a-counter-parameter-to-a-badge-query/133627>\
**Category:** Support\
**Created:** [11월 17, 2019, 9:41오후 UTC](https://meta.discourse.org/t/how-to-add-a-counter-parameter-to-a-badge-query/133627 "2019-11-17T21:41:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)\
**Post date:** [11월 17, 2019, 9:41오후 UTC](https://meta.discourse.org/t/how-to-add-a-counter-parameter-to-a-badge-query/133627/1 "2019-11-17T21:41:50Z")

</div>

안녕하세요,

특정 카테고리에 특정 키워드가 포함된 주제를 생성한 사용자에게 배지를 발급하기 위해 다음과 같은 배지 쿼리를 사용하고 있습니다:

```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 'Where to fly your drone in the UK'
) AND p.post_number = 1 AND p.raw LIKE '%dronescene.co.uk%' 
GROUP BY p.user_id
```

이 쿼리는 그동안 잘 작동해 왔으며, 이제 한 단계 더 발전시키고 싶습니다.

이 쿼리에 카운터를 추가하여, 이러한 조건을 충족하는 주제를 1개 생성한 사용자에게 동(Bronze) 배지, 5개 생성한 사용자에게 은(Silver) 배지, 10개 생성한 사용자에게 금(Gold) 배지를 발급할 수 있도록 하려면 어떻게 해야 할까요?

물론 배지마다 별도의 쿼리가 필요할 것임을 인지하고 있지만, 이 쿼리에 카운터를 추가하는 방법을 모르겠습니다.

도움을 주실 수 있는 분 있으신가요?

미리 감사드립니다 👍🏻

---

<div class="post-metadata">

**Author:** ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)\
**Post date:** [11월 17, 2019, 9:47오후 UTC](https://meta.discourse.org/t/how-to-add-a-counter-parameter-to-a-badge-query/133627/2 "2019-11-17T21:47:06Z")

</div>

쿼리 끝에 다음을 추가하면서 내 질문에 스스로 답을 한 것 같습니다:

`HAVING count(*) > 4`

제안된 결과를 확인/검증하기만 하면 됩니다.

---

<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:** [12월 17, 2019, 9:52오후 UTC](https://meta.discourse.org/t/how-to-add-a-counter-parameter-to-a-badge-query/133627/3 "2019-12-17T21:52:22Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
