I have a table containing people joining and leaving an organization.
Sample data: Sql Fiddle
| pId | pName | Unit | YearIn | Yea
I think you want a subquery and aggregation:
SELECT Year, Unit, SUM(NumIn) as NumIn, SUM(NumOut) as NumOut
FROM (SELECT YearIn AS Year, Unit, COUNT(pId) AS NumIn, NULL AS NumOut
FROM People
WHERE YearIn >= 2013
GROUP BY YearIn, Unit
UNION ALL
SELECT YearOut AS Year, Unit, NULL AS NumIn, COUNT(pId) AS NumOut
FROM People
WHERE YearOut >= 2013
GROUP BY YearOut, Unit
) yu
GROUP BY Year, Unit;