join to other table multiplied by loop foreign key in mysql
The issue of the amounts that are multiplied is easy to solve. You just have to use a derived table that does the calculation (group by) first and then join that (derived table) to the other one, that stores the hierarchical structure.

The derived table to use:

( SELECT userid,
         SUM(amount) AS sele_descendant_amount
  FROM webineh_user_buys 
  GROUP BY userid
  HAVING SUM(amount) &gt;= 1000
) AS buys 


Then we can join it to the other table. You also need to join it twice and that's another issue that may lead to a less efficient query. Unfortunately MySQL doesn't yet have CTEs, so the derived table code has to be duplicated. But you'll get at least a start with this code.

Tested at SQLfiddle:

SELECT
    buys_d.userid, 
    buys_d.sele_descendant_amount, 
    COUNT(*) AS level
FROM
    ( SELECT userid,
             SUM(amount) AS sele_descendant_amount
      FROM webineh_user_buys 
      GROUP BY userid
      HAVING SUM(amount) &gt;= 1000
    ) AS buys_d 
  JOIN
    webineh_prefix_nodes_paths AS users 
      ON  users.descendant_id = buys_d.userid 
  JOIN
    ( SELECT userid,
             SUM(amount) AS sele_descendant_amount
      FROM webineh_user_buys 
      GROUP BY userid
      HAVING SUM(amount) &gt;= 1000
    ) AS buys_a
      ON  users.ancestor_id = buys_a.userid 
GROUP BY
    buys_d.userid, buys_d.sele_descendant_amount ;