\u95ee\u9898<\/strong><\/div>\n\u5728\u9879\u76ee\u4e2d\u4f7f\u7528 Mysql \u4e2d\u7684 sum() \u51fd\u6570\u6c42\u548c\u65f6\uff0c\u8c03\u8bd5\u65f6\u53d1\u73b0\u62a5\u51fa\u4e0b\u9762\u7684\u9519\u8bef\u4fe1\u606f\uff1a<\/p>\n
sql: Scan error on column index 0, name \"total\": converting NULL to int64 is unsupported<\/pre>\n\u6211\u76f8\u5e94\u6267\u884c\u7684sql\u8bed\u53e5\u5982\u4e0b\uff1a<\/p>\n
SELECT SUM(consume) as total FROM task_income WHERE consume_type=3 AND uid=20;<\/pre>\n\u9a8c\u8bc1<\/strong><\/div>\n\u4e3a\u4e86\u627e\u5230\u539f\u56e0\uff0c\u6211\u5728 Navicat \u4e2d\u6267\u884c\u4e86\u4e00\u904d\u51fa\u95ee\u9898\u7684sql\u548c\u53c2\u6570\uff0c\u53d1\u73b0\u7ed3\u679c\u4e2d\u786e\u5b9e\u662f\u8fd4\u56de\u4e86 null :<\/p>\n
\u6309\u6211\u4e4b\u524d\u5f00\u53d1\u65f6\u7684\u60f3\u6cd5\uff1a<\/p>\n
\u5982\u679c\u6709\u76f8\u5e94\u7684\u6570\u636e\uff0c\u8fd4\u56de\u6c42\u548c\u540e\u7684\u503c<\/p>\n
\u5982\u679c\u6ca1\u6709\u7b26\u5408\u6761\u4ef6\u7684\u6570\u636e\uff0c\u8fd4\u56de 0<\/p>\n
\u7ed3\u679c\uff0c\u5f53\u6ca1\u6709\u7b26\u5408\u6761\u4ef6\u7684\u6570\u636e\u65f6\u5374\u8fd4\u56de\u4e86 null \u3002<\/p>\n
\u89e3\u51b3<\/strong><\/div>\n\u53ef\u4ee5\u901a\u8fc7\u7ed3\u5408\u4f7f\u7528 ISNULL \u6216 COALESCE \u51fd\u6570\u6765\u89e3\u51b3\u3002<\/p>\n
\u76f8\u5e94\u7684\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n
SELECT IFNULL(SUM(Column1), 0) AS total FROM...\r\n \r\nSELECT COALESCE(SUM(Column1), 0) AS total FROM...<\/pre>\n\u533a\u522b<\/strong><\/div>\n\u4e0a\u9762\u8bf4\u9053\uff0c\u4f7f\u7528 ISNULL \u6216 COALESCE \u51fd\u6570\u90fd\u53ef\u4ee5\u89e3\u51b3\u4e3a null \u7684\u95ee\u9898\uff0c\u90a3\u4e48\u8fd9\u4e24\u4e2a\u51fd\u6570\u6709\u4ec0\u4e48\u533a\u522b\u5462\uff1f<\/p>\n
ISNULL \u51fd\u6570\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\uff0c\u5982\u679c\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e0d\u662f null \u4f1a\u76f4\u63a5\u8fd4\u56de\uff0c\u5982\u679c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f null \uff0c\u5219\u8fd4\u56de\u7b2c\u4e8c\u4e2a\u53c2\u6570<\/p>\n
COALESCE \u51fd\u6570\u53ef\u4ee5\u63a5\u53d7\u4e24\u4e2a\u6216\u591a\u4e2a\u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u7b2c\u4e00\u4e2a\u975e null \u7684\u53c2\u6570\uff0c\u5982\u679c\u6240\u6709\u53c2\u6570\u90fd\u4e3a null\uff0c\u5219\u4f1a\u8fd4\u56de null<\/p>\n
\u53c2\u8003<\/strong><\/div>\nHow do I get SUM function in MySQL to return \u20180\u2019 if no values are found? - Stack Overflow\r\n\r\nsql - What is the difference bewteen ifnull and coalesce in mysql? - Stack Overflow<\/pre>\n\u5230\u6b64\u8fd9\u7bc7\u5173\u4e8eMysql\u4f7f\u7528sum()\u51fd\u6570\u8fd4\u56denull\u95ee\u9898\u7684\u6587\u7ae0\u5c31\u4ecb\u7ecd\u5230\u8fd9\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"
SUM()\u51fd\u6570\u7528\u4e8e\u8ba1\u7b97\u4e00\u7ec4\u503c\u6216\u8868\u8fbe\u5f0f\u7684\u603b\u548c\uff0cSUM()\u51fd\u6570\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a SUM(DISTINCT expres […]<\/p>\n","protected":false},"author":362,"featured_media":11367,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-235232","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/235232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=235232"}],"version-history":[{"count":3,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/235232\/revisions"}],"predecessor-version":[{"id":235235,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/235232\/revisions\/235235"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/11367"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=235232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=235232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=235232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}