Here is a Reply by Email Badge:
select
p.user_id
,min(p.created_at) granted_at
,min(p.id) post_id
from badge_posts p
where
(:backfill or p.id IN (:post_ids) )
and p.post_number >1
and p.via_email=True
group by
p.user_id