You are viewing a single comment's thread. Return to all comments →
MS SQL SERVER-
SELECT CEILING(AVG(CAST(SALARY AS DECIMAL))-AVG(CAST(REPLACE(SALARY,0,'')AS DECIMAL))) FROM EMPLOYEES;
For those, who are getting the wrong result as 2252 and not actual 2253, this is because of the first query- AVG(SALARY)
In SQL Server, AVG function returns the result as integer even if the real result is decimal and that's why query is failing.
So, you have to encapsulate this query under cast too- AVG(CAST(SALARY AS DECIMAL)) Now, write together the whole query and you'll get the answer.
Seems like cookies are disabled on this browser, please enable them to open this website
The Blunder
You are viewing a single comment's thread. Return to all comments →
MS SQL SERVER-
SELECT CEILING(AVG(CAST(SALARY AS DECIMAL))-AVG(CAST(REPLACE(SALARY,0,'')AS DECIMAL))) FROM EMPLOYEES;
For those, who are getting the wrong result as 2252 and not actual 2253, this is because of the first query- AVG(SALARY)
In SQL Server, AVG function returns the result as integer even if the real result is decimal and that's why query is failing.
So, you have to encapsulate this query under cast too- AVG(CAST(SALARY AS DECIMAL)) Now, write together the whole query and you'll get the answer.