Ich denke, eine einfache Version wäre so etwas wie diese:
SELECT
t.user_id,
CURRENT_TIMESTAMP AS granted_at,
p.id AS post_id
FROM topics t
JOIN posts p ON p.topic_id = t.id AND p.post_number = 1
WHERE t.posts_count >= 100
AND t.archetype = 'regular'
AND t.deleted_at ISNULL
AND t.user_id > 0
Die Verwendung von t.post_counts würde derzeit auch die kleinen Aktionsbeiträge (geschlossen, nicht aufgeführt usw.) einschließen, daher hängt es davon ab, wie genau es sein soll.
Sie könnten es spezifischer machen, indem Sie die Anzahl der “berechtigten” Beiträge innerhalb der Abfrage zählen. Etwas wie:
SELECT
t.user_id,
CURRENT_TIMESTAMP AS granted_at,
p.id AS post_id
FROM topics t
JOIN posts p ON p.topic_id = t.id AND p.post_number = 1
WHERE t.id IN (
SELECT
p.topic_id
FROM posts p
JOIN topics t ON t.id = p.topic_id
WHERE t.archetype = 'regular'
AND t.deleted_at IS NULL
AND p.deleted_at IS NULL
AND p.post_number <> 1
AND p.post_type = 1
AND p.hidden IS FALSE
GROUP BY 1
HAVING COUNT(*) >= 100
)