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

How to sum the values of two columns and have it in a new one?

I’m trying to sum the values of two columns into a new one, its for analysis purpose (not creating a new column in the database)
I tried using case statement but I have no idea what is happening :
(Basically what I’m trying to say is: if the sum of the 2 columns is equal or grater than one, then count it as 1, if its 0 or null then skip and return zero)
please see the attached pictures

enter image description here

enter image description here

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 :

Your case statement should look like this to handle null values properly.

SELECT CASE WHEN COALESCE(speciality_count, 0) + COALESCE(Italian_count, 0) > 0
                 THEN 1
            ELSE 0
       END AS TwoCount
FROM table_name 
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