鍍金池/ 問答/數(shù)據(jù)庫/ mysql表中計算資料完善度

mysql表中計算資料完善度

有一個students表,一共10個字段:

id name gender age class from father mother address nationality 

我想計算一個student的資料完善度,計算公式就是:

(9-空字段數(shù))/9*100%    //去除id字段

問題:
在mysql中怎么獲得一條記錄的空字段數(shù)或不為空的字段數(shù)?

回答
編輯回答
練命
select a_v+b_v+c_v+...
from (select 
        case when a is null then 1 else 0 end a_v,
        case when b is null then 1 else 0 end b_v,
        ...
      from table
      where ...) aa;
2017年12月15日 06:18
編輯回答
款爺
select isnull(name)+isnull(gender)+isnull(age) as score from students

就寫了三個字段,我就不幫你補(bǔ)全了哈

2017年12月31日 00:39