Bonjour à tous,
J'essaie d'obtenir la somme totale gagnée par un client référrant ses clients référés (donc système d'affiliation) avec une requête sur 2 tables, mais sans succès.
La structures des tables :
1° factures
id | user_id | amount | paid
1 ---- 3 ------- 5.50 ---- 0
2 ---- 3 ------- 1.20 ---- 1
3 ---- 5 ------- 2.30 ---- 1
4 ---- 8 ------- 7.50 ---- 1
2° clients
c_id | c_referrerid | c_referredid
1 --------- 1 ------------- 3
2 --------- 1 ------------- 5
3 --------- 1 ------------- 8
et factures.user_id=clients.c_referredid
sachant qu'un c_referrerid peut avoir plusieurs c_referredid (affiliés)
Voici comment j'ai construit ma requête:
$query_total = "SELECT c.c_referredid, f.*, SUM(f.amount) AS total FROM clients c
LEFT JOIN " . DB_PREFIX . "factures f ON f.user_id=c.c_referredid
WHERE c.c_referrerid=1
GROUP BY f.paid=1 ";
$total_result = mysql_query($query_total);
$row_résult = mysql_fetch_array($total_result);
echo $row_result['total'];
Et le total ne correspond pas du tout, j'ai un chiffre incohérant.
Merci pour votre aide
