We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Do you know why this code wouldn't have worked in MS SQL?
select ceiling (avg(salary)) - avg(replace( salary, 0, '')) from employees
I've always known AVG to work with integers and it specifies in the problem that Salary has data type INT. When I run the code it thinks it's working with VARCHAR.
Fixed with CAST function but I don't understand why we need to CAST in MS SQL
Cookie support is required to access HackerRank
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 →
Do you know why this code wouldn't have worked in MS SQL?
select ceiling (avg(salary)) - avg(replace( salary, 0, '')) from employees
I've always known AVG to work with integers and it specifies in the problem that Salary has data type INT. When I run the code it thinks it's working with VARCHAR.
Fixed with CAST function but I don't understand why we need to CAST in MS SQL