DynDeveloper.com

DynDeveloper.com

Sign Up Now!Log In
acabot 10/20/2016 4:52:54 PM

Trying To Figure Out SQL Query Behavior

I have this query:

USE SIZE

select e1.[Division] AS 'Division', Sum(e1.[July Emp Count]) AS 'Month1 Emp Count', Sum(e2.[Aug Emp Count]) AS 'Month2 Emp Count', Sum(e3.[Sept Emp Count]) AS 'Month3 Emp Count'

into #emp_total

from #emp e1

JOIN #emp2 e2 ON e1.Division=e2.Division

JOIN #emp3 e3 ON e1.Division=e3.Division

group by e1.division order by e1.Division

GO

select * from #emp_total order by division

--------------------------------------------------

The results in the three "Emp Count" columns doubles each time I add one of the JOINs.  Why?

For example, in this result:

Division Month1 Emp Count Month2 Emp Count Month3 Emp Count
120      68                68                76

These three counts SHOULD be 17, 17 and 19

Version: GP 2013
Section: SQL Scripts