3 tables join and sum | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

3 tables join and sum

How to join 3 tables and calculate the Sum of a field of them? table A : id , name 1 | John 2 | Paul 3 | Eric Table B: id, amountb 1 | 50 1 | 35 2 | 20 Table C: Id, amountc 2 | 12 3 | 14 3 | 7 I want to join tables grouped id and SUM (amounta), sum (amountb), sum (amountc). Note I tried this code but it make make wrong calculation: Select Id, name, SUM(amountb), SUM(amountc) From A Left join B on A.id= B.id Left join C on A.id= c.id Group by A.id I want result to be Id | name | amountb | amountc 1 | John | 85 | null 2 | Paul | 20 | 12 3 | Eric | null | 21

27th Jun 2018, 7:43 AM
Yahia Baiba
Yahia Baiba - avatar
3 Answers
0
Tell us 3 data each from each Table or just remove left join to just join ie inner join
27th Jun 2018, 4:37 PM
ᴋᵘⁿᵃˡ
ᴋᵘⁿᵃˡ - avatar
0
i’ve edited the question to add data. thank you Kunal Thakur
27th Jun 2018, 8:40 PM
Yahia Baiba
Yahia Baiba - avatar
- 1
Left join C on A.id= c.id The problem is in with this it should be C.Id Left join C on A.id= C.Id Its a case sensitive if you want to use column name capital then use capital all if camecase or lowercase so stick to one only and follow in your project.I use camecase btw.
28th Jun 2018, 3:42 PM
ᴋᵘⁿᵃˡ
ᴋᵘⁿᵃˡ - avatar