What happens to SUM and TOTAL when no fees match?

SQLite SUM returns NULL for an empty set of non-null inputs. TOTAL returns floating-point zero.

SQLite example and interpretation

An empty ledger can represent missing activity or a displayed zero. Include the row count to distinguish it from trades whose fees cancel out.

WITH fees(x) AS (VALUES(9)) SELECT sum(x),total(x),count(*) FROM fees WHERE x<0;

Result [[null, 0.0, 0]]

中文

没有匹配费用时,SUM 和 TOTAL 各返回什么?

SQLite 的 SUM 在没有非空输入时返回 NULL,TOTAL 返回浮点零。

SQLite 示例与适用条件

查一本空账本时,报表可选择零或缺数据。若要区分没有交易和交易金额正好抵消,应同时看交易笔数。

WITH fees(x) AS (VALUES(9)) SELECT sum(x),total(x),count(*) FROM fees WHERE x<0;

结果 [[null, 0.0, 0]]

References / 参考来源

Keep reading / 继续阅读