Badge for posting image in specific topic

Please proof my work…I installed Data Explorer which dramatically helped me understand the database structure as well as the ability to try out some queries. From what I can tell, this will pull if you have uploaded an image to a specific topic.

set topic_id (6th line) as the topic for the badge.

SELECT DISTINCT ON (sub.user_id)
sub.user_id, sub.post_id, sub.created_at granted_at from (SELECT p.created_at, p.user_id, p.id as post_id,
    length(raw) * 2
      - length(replace(raw, '<img', '123'))
      - length(replace(raw, '[img]', '1234')) as num
  FROM posts p where topic_id=62) sub
  where sub.num > 0 AND (:backfill OR sub.post_id IN (:post_ids) )

Updated. Needed to have the ‘granted_at’ as well as post_ids