我有以下查询,如果他们在个人资料中输入字段,则显示0或1。
select id,
count(users.firstname),
count(users.lastname),
count(users.gender),
count(users.country),
count(users.address_one),
count(users.city),
count(users.zipcode),
count(users.housenumber),
count(users.phonenumber),
count(users.educationlevel_id)
from users
group by id;
如何将所有计数加起来并按ID分组?
select id, SUM(
count(users.firstname)+
count(users.lastname)+
count(users.gender)+
count(users.country)+
count(users.address_one)+
count(users.city)+
count(users.zipcode)+
count(users.housenumber)+
count(users.phonenumber)+
count(users.educationlevel_id)
) as smartbio_check
from users
group by id, smartbio_check;
此查询无法正常工作
答案 0 :(得分:1)
只需添加count
值:
select id,
count(users.firstname) +
count(users.lastname) +
count(users.gender) +
count(users.country) +
count(users.address_one) +
count(users.city) +
count(users.zipcode) +
count(users.housenumber) +
count(users.phonenumber) +
count(users.educationlevel_id) as smartbio_check
from users
group by id