SELECT User, COUNT(*) as count FROM Tests GROUP by User;
这可能会返回行,其中User为null但count为某个数字。如何修改查询而不是空(null)行我可以看到一些字符串?
答案 0 :(得分:4)
通常情况下,我建议coalesce
自动将空值转换为其他值,但看起来MsAccess可能没有。您可以尝试使用nz
:
select nz(user, '<<NULL>>') as user,
count(*) as count
from tests
group by user
代替。
您可能还会发现它更有效(这当然取决于您的DBMS)完全摆脱每行功能和union
两个单独的查询,如:
select user as user, count(*) as count
from tests
where user is not null
group by user
union all select '<<NULL>>' as user, count(*) as count
from tests
where user is null
但是,MsAccess是否允许(或者你是否关心),我不知道。我知道它最有可能在我使用的主DBMS上表现更好但你应该永远记住:测量,不要猜测!