Remove the "a" at the end of the first line - see in red below:select a.memberid,sum(a.MonthlyBonus)as MonthlyBonus,sum(a.FestivalBonus)as FestivalBonus,(a.OfficerBonus)as OfficerBonus from a
(
...
You can shorten the code as shown below, which would avoid the UNION ALL and the subquery, and so is likely to be more efficient as wellSELECT
memberid,
SUM(CASE WHEN tag = 'MB' THEN amount ELSE 0 END) AS MonthlyBonus,
SUM(CASE WHEN tag = 'FB' THEN amount ELSE 0 END) AS FestivalBonus,
SUM(CASE WHEN tag = 'OB' THEN amount ELSE 0 END) AS OfficerBonus
FROM
tblmember_comission
GROUP BY
memberid;