# Возможность удаления тегов с \< N темами

**URL:** <https://meta.discourse.org/t/ability-to-delete-tags-with-n-topics/159979>\
**Category:** Feature\
**Tags:** tags\
**Created:** [06.Август.2020 05:37:40 UTC](https://meta.discourse.org/t/ability-to-delete-tags-with-n-topics/159979 "2020-08-06T05:37:40Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![mcwumbly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcwumbly/32/103861_2.png) [@mcwumbly](https://meta.discourse.org/u/mcwumbly)\
**Post date:** [09.Август.2020 21:36:24 UTC](https://meta.discourse.org/t/ability-to-delete-tags-with-n-topics/159979/5 "2020-08-09T21:36:24Z")

</div>

Тем временем, вот запрос #plugin:data-explorer, который поможет пользователям определить кандидаты на удаление тегов:

```plaintext
-- [params]
-- int :months_since_used = 24
-- int :max_topic_count = 50

with
t as (
  select 
    current_date::timestamp - (:months_since_used * (INTERVAL '1 months')) as cutoff_date
),
topic_tag_dates as (
  select tags.id, tags.name, tags.topic_count, topics.last_posted_at as last_used
  from topic_tags
  left join tags
  on topic_tags.tag_id = tags.id
  left join topics
  on topic_tags.topic_id = topics.id
),
max_last_used as(
  select id, max(last_used) mx from topic_tag_dates
  group by id
),
tag_last_used as (
  select topic_tag_dates.id, name, topic_count, last_used from topic_tag_dates
  left join max_last_used
  on topic_tag_dates.id = max_last_used.id
  where max_last_used.mx = topic_tag_dates.last_used
)
select id,name,topic_count,last_used from tag_last_used, t
  where tag_last_used.last_used < t.cutoff_date
  and topic_count < :max_topic_count
  order by topic_count desc

```

---

_[View the full topic](https://meta.discourse.org/t/ability-to-delete-tags-with-n-topics/159979)._
