SELECT
*
FROM styper_user usr
LEFT JOIN styper_group grp
ON grp.groupid = usr.groupid
LEFT JOIN
(
SELECT userid, count(*) as score
FROM styper_referer
GROUP BY userid
) cntall
ON cntall.userid= usr.userid
LEFT JOIN
(
SELECT
userid,
COUNT(*) as actscore
FROM
(
SELECT
newid,
userid,
COUNT(*) as actscore
FROM
(
SELECT DISTINCT
ref.newid as newid,
ref.userid as userid,
ro.roundid as roundid
FROM
styper_type t
LEFT JOIN styper_match m ON m.matchid = t.matchid
LEFT JOIN styper_round ro ON ro.roundid = m.roundid
JOIN styper_referer ref ON ref.newid = t.userid
WHERE
t.userid = ref.newid
) cnt
GROUP BY newid
HAVING
actscore > 2
) counter
GROUP BY
userid
) cntused
ON cntused.userid = usr.userid
WHERE cntall.score > 0
Table '1147300_KzE.styper_user' doesn't exist