Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Average using case

I am trying to get a column that returns ‘yes’ or ‘no’ if the average price is higher or lower than 6000.
the script I am writing returns an error saying "Operand data type varchar is invalid for avg operator"

here is my script, how should I correct it?

select avg(case when BASIC_SALARY >6000 then 'yes'
else 'no' 
end )as 'above_6000'
from workers_table

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You just need to change the position of the average function.

SELECT CASE WHEN AVG(BASIC_SALARY) >6000 
            THEN 'yes'
            ELSE 'no' 
       END AS 'above_6000'
FROM workers_table
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading