我需要组合一种方法,使我能够量化用户已填充一行中的多少个字段。
例如:
User Name Age Country Gender Height
1 Mike 34 USA Male 6
2 Bill 23 CA 5
3 Jane 31 USA
在上面的例子中,我想查询数据库并返回一个反映用户记录完成程度的值。例如:
User 1 = 100% complete
User 2 = 80% complete
User 3 = 60% complete
我想知道这是否需要通过 SQL 子句来完成,或者是否可以通过 PHP SQL 函数查询数据库并计算完成度。
有什么建议如何做到这一点?我正在使用 PHP 5 (codeigniter) 和 SQL 5.0.77,但任何路线图将不胜感激。
select
User,
(
case Name when '' then 0 else 1 end
+
case when Age is null then 0 else 1 end
+
case Country when '' then 0 else 1 end
+
case Gender when '' then 0 else 1 end
+
case when Height is null then 0 else 1 end
) * 100 / 5 as complete
根据无信息的含义使用大小写:空或 null。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)