I have this table that I need to sort in the following way:
- need to rank Departments by Salary;
- need to show if Salary = NULL - 'No data to be shown' message
- need to add total salary paid to the department
- need to count people in the department
SELECT RANK() OVER (
ORDER BY Salary DESC
)
,CASE
WHEN Salary IS NULL
THEN 'NO DATA TO BE SHOWN'
ELSE Salary
,Count(Fname)
,Total(Salary) FROM dbo.Employees
I get an error saying:
Column 'dbo.Employees.Salary' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY
clause.
Why so?