Tableau un (tableau Auteur)J'ai 3 tables comment les joindre pour générer une table?
author_id author_name
Tableau b (post Table)
post_id author_id
Tableau c (Earning tableau)
post_id (post id is not unique) post_earning
Je voulais générer un rapport constitué des gains par auteur.
author_id author_name total_earning (sum of earnings of all the posts by author)
La requête SQL utilisée:
SELECT
a.author_id,
a.author_name,
sum(post_earnings) as total_earnings
FROM TableA a
Inner Join TableB b on b.author_id = a.author_id
Inner Join TableC c on c.post_id = b.post_id
Group By
a.author_id,
a.author_name
Le résultat je suis arrivé est la suivante:
ID user_login total_earnings 2 Redstar 13.99 7 Redleaf 980.18 10 topnhotnews 80.43 11 zmmishad 39.27 13 rashel 1248.34 14 coolsaint 1.66 16 hotnazmul 9.83 17 rubel 0.14 21 mahfuz1986 1.09 48 ripon 12.96 60 KHK 27.81
la somme des gains au total est en fait 2863,22. Mais si j'ajoute toute la valeur de la table de résultat, je reçois 2415. Où est le problème? Les exemples de tableaux utilisés peuvent être téléchargés à partir des liens dans le premier commentaire.
Vous avez raison, j'ai eu quelques messages absents dans le tableau de la poste. Un gourou sql dans le forum de sitepoint l'a compris. Merci pour votre réponse. – coolsaint