Adding hierarchy points

0

My goal is to create a multi-level marketing system, with two teams.

Left and Right Team

I'm having trouble counting points.

My table looks like this:   id_user | sponsor | leg (0 left, 1 right) | points

Remembering that the network has no limit and that the sum of points on the left, for example, includes all the points of the respective downlines.

I need help to make this point count.

    
asked by anonymous 26.04.2017 / 04:09

1 answer

0
To add, use the SQL function SUM() , but to use it you need to group your records with GROUP BY passing all the fields you want to search, do not use c.* , just take the fields that are really needed for your application.

Example:

 SELECT c.id_usaurio,
       c.patrocinador,
       c.perna,
       sum(c.pontos) AS TotalPontos
FROM cic_ciclone_users p
INNER JOIN cic_ciclone_users c ON c.patrocinador = p.id_user
GROUP BY C.id_usuario,
         c.patrocinador,
         c.perna
    
26.04.2017 / 13:55