This is my query,
SELECT TOP (3)
a.INCIDENT_ID, a.REFERENCE, SUM(b.COST) AS TOTAL_COST
FROM
FDDC_T_D_INCIDENT AS a
INNER JOIN
FDDC_T_D_INCIDENT_COST AS b ON a.INCIDENT_ID = b.FINCIDENT_ID
WHERE
(a.CREATED_DATE >= @date1) AND (a.CREATED_DATE <= @date2)
GROUP BY
a.INCIDENT_ID
ORDER BY
TOTAL_COST DESC
I'm getting an error
Column 'FDDC_T_D_INCIDENT.REFERENCE' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Can someone please help me with this issue?
Thanks in advance!