I'm trying to obtain the average of not null fields in a query. Right now I'm making:
select COUNT(name) as name
,COUNT(surname) as surname
,COUNT(email) as email from table where id = 1
And then I manually sum all and then calculate the average making a division with the total fields. I'm sure there is a more automatic ad elegant way of doing that but I'm not seeing it
Thanks!
EDIT EXAMPLE
query result:
Name Surname Email
-----------------------------
John Lennon NULL
Mary NULL NULL
Peter Clock 222@aa.com
total fields: 9 no-null fields: 6
average no null fields: 6/9 = 0,66 -> 66% Thats what I want
sorry for not being clear