khtan unfortenately wrote INNER JOINs that behave like CROSS JOIN due to multiple Fks.Look at this exampleDECLARE @a TABLE (pk INT)DECLARE @b TABLE (fk INT, i INT)DECLARE @c TABLE (fk INT, j INT)INSERT @aSELECT 1 UNION ALLSELECT 2 UNION ALLSELECT 3INSERT @bSELECT 1, 1 UNION ALLSELECT 1, 3 UNION ALLSELECT 2, 4 UNION ALLSELECT 2, 8 UNION ALLSELECT 2, 10 UNION ALLSELECT 3, 1INSERT @cSELECT 1, 11 UNION ALLSELECT 1, 13 UNION ALLSELECT 2, 14 UNION ALLSELECT 2, 18 UNION ALLSELECT 2, 60 UNION ALLSELECT 3, 11select a.pk, SUM(b.i) AS SumAct, SUM(c.j) AS SumDebtfrom @a as ainner join @b as b on b.fk = a.pkinner join @c as c on c.fk = a.pkgroup by a.pk
I think sum 276 is to high! Should only be 92.The reason for this is that there also is 3 records in @b table that share same fk. 92 times 3 is 276.
E 12°55'05.25"N 56°04'39.16"