select all rows for which there are at least 30 instaces of an id within an association table

Hmmm . . . use window functions:

SELECT ptt.*
FROM (SELECT ptt.*,
             COUNT(*) OVER (PARTITION BY ptt.tag_id) as cnt
      FROM PostToTag ptt 
     ) ptt
WHERE cnt >= 30;

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top