Anda dapat menyederhanakan kueri Anda, dan menggunakan LEPAS fungsi
SELECT USERid, LEAST(7, COUNT(*))
FROM table
GROUP BY USERid
dari pertanyaan di komentar Anda
SELECT SUM(countByUser)
FROM
(SELECT LEAST(7, COUNT(*)) as countByUser
FROM table
GROUP BY USERid) c