I have one that I was playing with, though I put it to one side to look at it with fresh eyes and haven’t got back to it yet, so it may need some work. It’s to award a badge based on getting at least 10 posts with the
reaction given by a member of the ‘data-team’ group for posts in the #data-reporting category:
SELECT p.user_id, MIN(p.created_at) granted_at
FROM badge_posts p
JOIN topic_tags tt ON tt.topic_id = p.topic_id
WHERE tt.tag_id = 615
AND EXISTS (
SELECT 1
FROM discourse_reactions_reactions dr
JOIN discourse_reactions_reaction_users dru ON dr.id = dru.reaction_id
JOIN group_users gu ON gu.user_id = dru.user_id
WHERE dr.post_id = p.id
AND dr.reaction_value = 'chefs_kiss'
AND gu.group_id = 175
)
GROUP BY p.user_id
HAVING COUNT(*) >= 10
Though I wasn’t pleased with using the MIN as it gave the wrong awarded date.
There’s a lot of criteria to it, and it’s automatic, which I think pushes it to the more complicated end. I think a simpler one could be much more achievable without too much effort.