You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MySQL中COUNT()与WHERE子句返回0或空集问题求助

MySQL查询匹配不到预期数据(CSV导入后)

我建了数据库和phones表,把CSV文件导入后,表包含state和phone_condition等字段。之前大部分查询都正常,但下面几个简单查询死活出不来预期结果,翻了Stack Overflow试了各种方法都没用。

试过的查询和结果

  • 执行这条SQL:
select state, phone_condition, count(phone_condition) as lagosUsedphones
from phones
where state='Lagos' and phone_condition='Used';

返回结果:

statephone_conditionlagosUsedphones
NULLNULL0
  • 执行这条:
select state, phone_condition from phones where state='lagos' and phone_condition='used';

直接返回 Empty set (0.01 sec)

  • 尝试CASE语句查询:
select h.state, count(
case when phone_condition='Used' and state='Lagos' then 1 else null end) as usedLagosPhones
from phones h;

结果统计出的数量仍为0

  • 还执行了这条:
select count(state and phone_condition) as LagosUsedPhones from phones
where state='Lagos' and phone_condition='Used';

返回结果还是0

额外说明

  • 直接查看表时,明明能看到state为Lagos、phone_condition为Used的行
  • 执行 select count(*) from phones where state is null and phone_condition is null; 返回0,说明这两个字段没有空值
  • 导入的CSV样本里,确实存在state列值为Lagos、phone_condition列值为Used的条目

内容的提问来源于stack exchange,提问作者Kelly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 14:32:17