Lets suppose You have executed the given query in SQL SERVER .
CREATE TABLE [dbo].[Employee](
[ID] [int] NOT NULL,
[Name] [varchar](50) NULL,
[Salary] [numeric](18, 0) NULL,
[DepartmentID] [int] NULL,
[ContactNo] [numeric](18, 0) NULL,
)
From this table, You want to return the records of employee who has highest Salary.
SELECT [ID],
MAX(MAX(Salary) - MIN(Salary)) AS [HighSalary]
FROM [dbo].[Employee]
GROUP BY [ID]
Error Message :
But getting the below error.
Msg 130, Level 15, State 1, Line 2
Cannot perform an aggregate function on an expression containing an aggregate or a subquery.
Causes:
In Above statement,you are using aggregate function on SubQuery that is already using aggregate function
Solution of the Error:
To avoid this type of error, Please ensure that There are using aggregate function on a subquery which has no other aggregate function.
SELECT [ID],
(MAX(Salary) - MIN(Salary)) AS [HighSalary]
FROM [dbo].[Employee]
GROUP BY [ID]
If you want to sell your readymade software to the genuine clients or businessman, list your software with details and demo links.
Clients will find it using our advanced search filter and will contact you directly.
No any charge for the product lsiting.