complementing the previous post:
this query makes a list of an item where msgid is found many times than 4,
and you can use its number as CountOfmsgid...
SELECT flag_rest_spam.msgid, Count(flag_rest_spam.msgid) AS CountOfmsgid
FROM flag_rest_spam
GROUP BY flag_rest_spam.msgid
HAVING (CountOfmsgid > 4);