SELECT
  X.Batch,
  X.ClientID,
  X.ClientName,
  X.EmailAddress,
  X.DateJoined,
  (SUM(X.Increase) / SUM(X.OldRetainer) * 100) AS RetainerIncreasePercentage,
  SUM(X.OldRetainer) AS OldRetainer,
  SUM(X.Increase) AS Increase,
  SUM(X.NewRetainer) AS NewRetainer
FROM (

@pInnerSQL

) AS X
GROUP BY 1,2,3,4,5
ORDER BY X.ClientID
