I've created an SqlFiddle <http://www.sqlfiddle.com/#!18/b9363f/4> to explain my problem

I have three entities "Invoice"->1:n->"Payment"->1:n->"Taking"

Each entity has it's own Total (amount), i have to write a SELECT that sums the amount (of each entity) to match the ampount of the parent... The problem is on the "Payments" that are replied for each Taking.

```
SELECT I.invoice_number AS invoiceNumber, I.amount AS invoiceAmount, SUM(P.amount) AS paymentAmount, SUM(T.amount) as takingAmount 
FROM Invoice AS I
INNER JOIN Payment AS P ON P.invoice_number = I.invoice_number
INNER JOIN Taking AS T ON T.invoice_number = P.invoice_number AND T.payment_row = P.payment_row
GROUP BY I.invoice_number, I.amount, P.invoice_number

```

Result is (first row wrong)

```
invoiceNumber   invoiceAmount   paymentAmount   takingAmount
1               100.2           300.4           100.2
2               98.4            98.4            98.4

```

How can i group this one avoiding the "amount" of the Payments "replyed"

**[EDITED]**
Result Expected

```
invoiceNumber   invoiceAmount   paymentAmount   takingAmount
1               100.2           100.2           100.2
2               98.4            98.4            98.4

```