SELECT SUM( reward ) , tgid
FROM answer
WHERE tgid
IN (
SELECT tgid
FROM question
WHERE isactual != '0'
AND EXTRACT(YEAR_MONTH FROM dateadd) = EXTRACT(YEAR_MONTH FROM CURRENT_DATE())
GROUP BY tgid
HAVING COUNT( * ) >=1
)
AND tgid
IN (
SELECT referral
FROM user
WHERE EXTRACT(YEAR_MONTH FROM date_reg) = EXTRACT(YEAR_MONTH FROM CURRENT_DATE())
GROUP BY tgid
HAVING COUNT( * ) >=1
)
AND EXTRACT(YEAR_MONTH FROM dateadd) = EXTRACT(YEAR_MONTH FROM CURRENT_DATE())
ORDER by SUM( reward ) DESC LIMIT 10
EXTRACT(YEAR_MONTH FROM CURRENT_DATE())
&
, если с ней вставить в брайзер то не уходит, а если заменить на &, то работает