【问题标题】:Problems with SUM in mysqlmysql中SUM的问题
【发布时间】:2018-03-18 09:20:51
【问题描述】:

我有一个表“Cabine”,其中包含“SBC750”(整数)和“Evaso”(tinyint)字段

字段 Evaso 可以是 1、0 或 Null

我正在寻找 Evaso 不是 1 的所有 sbc750 的总和。

我试过了

select sum(sbc750) from cabine  where evaso<>1;

但是结果是NULL:为什么???

如果我使用

select sum(sbc750) from cabine 

我得到 55,如果我使用

select sum(sbc750) from cabine where evaso=1

我得到了 34 个!

所以结果可能是 21 而不是 Null。请帮帮我

【问题讨论】:

  • 从机柜 WHERE evaso>1 OR evaso 中选择 SUM(sbc750) 怎么样
  • select sum(sbc750) from cabine where evaso IS NULL
  • 我同意 Sari .. 我有一种感觉,&lt;&gt; 1 你返回的结果为零.. 试试select * from cabine where evaso&lt;&gt;1; 来测试这个理论..
  • 是的 1 没有结果.. Sari 的建议不起作用。 lad2025 的一个。

标签: mysql


【解决方案1】:

使用NULL-safe 相等运算符,您应该会得到想要的结果:

select sum(sbc750) from cabine where not evaso<=>1;

另请参阅here 以供参考。

【讨论】:

    【解决方案2】:
    SELECT sum(sbc750) FROM cabine where evaso is null or evaso<>1;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-25
      相关资源
      最近更新 更多