How to calculate the sum of column alias "Performance_Indicators". I want to total the sum of Performance_Indicator. I cannot use SUM(Performance_Indicators).
SELECT a.username
,a.name
,a.description
,a.action_header
,a.remarks
,e.complexity
,datediff(DAY, e.entry_date, a.datetime_stamp) as [man-days]
,CASE
WHEN e.complexity = 'Simple' AND datediff(DAY, e.entry_date, a.datetime_stamp)
= 0 THEN '1'
WHEN e.complexity = 'Simple' AND datediff(DAY, e.entry_date, a.datetime_stamp)
>= 29 THEN '2'
WHEN e.complexity = 'Simple' AND datediff(DAY, e.entry_date, a.datetime_stamp)
>= 14 THEN '3'
WHEN e.complexity = 'Simple' AND datediff(DAY, e.entry_date, a.datetime_stamp)
>= 8 THEN '4'
WHEN e.complexity = 'Simple' AND datediff(DAY, e.entry_date, a.datetime_stamp)
<= 7 THEN '5'
ELSE '1'
END AS Performance_Indicators,
SUM(Performance_Indicators) as total
from [s].[dbo].[tbl_de] a
left join
[s].[dbo].[tbl_ce] e
on a.reference_code = e.reference_code
order by a.name asc

GROUP BYto your query and select that sum for each group.