Arjun Dhilod

Arjun Dhilod

  • 800
  • 812
  • 107.4k

getting error in sql when doing sum of two column

Oct 2 2018 7:28 AM
This sql query is not working the error are as below 
"Each GROUP BY expression must contain at least one column that is not an outer reference".
Kindly help me if some know solution of it. 
 
SELECT DISTINCT SUM(IncentiveBreakups.ActivationAmount + UniqueActivationAmount) AS Monthly,
IncentiveBreakups.ActivationAmount AS [Activation],
Case when Agents.JoiningDate >= '2018-10-01' THEN UniqueActivationAmount ELSE 0 END AS UniqueActivation
FROM Incentives
INNER JOIN IncentiveBreakups ON IncentiveBreakups.IncentiveID = Incentives.ID
INNER JOIN IncentiveSheets ON IncentiveSheets.ID = Incentives.IncentiveSheetID
INNER JOIN IncentiveSheetUsers ON IncentiveSheetUsers.IncentiveSheetID = IncentiveSheets.ID
INNER JOIN Achievements ON IncentiveSheetUsers.UserID = Achievements.UserID
INNER JOIN Agents ON Achievements.AgentID=Agents.ID
AND IncentiveBreakups.IncentiveID = Incentives.ID
AND IncentiveBreakups.Activations = (SELECT COUNT(DISTINCT Achievements.AgentID) AS Count FROM Achievements
WHERE CONVERT(DATE, Achievements.CreatedOn) BETWEEN '2018-09-01' AND '2018-09-30'
AND Achievements.UserID = 23
GROUP BY IncentiveBreakups.ActivationAmount,UniqueActivationAmount
HAVING SUM(CONVERT(FLOAT, Achievements.GWP)) > 8000)
 

Answers (4)