-1

I'm writing a query where i have to get the count of not null columns of each row in mysql similar to countA function in excel. can anyone help me in acheving the desired result as shown in the table below.

enter image description here

1 Answers1

0

I am not sure if we have any direct function for this need. I tried using if condition. I hope it would be useful.

SELECT Column_1,Column_2,Column_3, if(Column_1 is null,0,1) + if(Column_2 is null,0,1) + if(Column_3 is null,0,1) as total from table

Praveen E
  • 926
  • 8
  • 14
  • Thanks Praveen, I Previously tried the same logic with case condition but when the number of columns increases it becomes difficult to write a large number of case statements – nachappa p r Dec 07 '18 at 14:51