USER用户表,字段:USERID,NAME,SEX,PASS
要统计一个用户即一条记录里面空字段的个数,即统计用户资料的完善程度,怎么做呢?
谢谢大家哈

解决方案 »

  1.   

    select 资料完善度=(case when USERID is not null then 1 else 0
    +case when [NAME] is not null then 1 else 0  
    +case when SEX is not null then 1 else 0  
    +case when PASS is not null then 1 else 0)*1.0/4
    from [USER] 
      

  2.   

    --1楼的少个end
    select 资料完善度=(case when USERID is not null then 1 else 0 end
    +case when [NAME] is not null then 1 else 0 end 
    +case when SEX is not null then 1 else 0 end  
    +case when PASS is not null then 1 else 0 end)*1.0/4
    from [USER] 
      

  3.   

    declare @tb table (USERID int,NAME varchar(100),SEX varchar(100),PASS varchar(100))
    insert into @tb select 1,null,null,'aa' select *,
    sum(case when [name] is null then -1 else 0 end+
    case when SEX is null then -1 else 0 end+
    case when PASS is null then -1 else 0 end) as 完善程度
    from @tb group by USERID,NAME,SEX,PASS1 NULL NULL aa -2