{"id":84919,"date":"2020-05-15T04:49:59","date_gmt":"2020-05-14T20:49:59","guid":{"rendered":""},"modified":"2020-05-15T04:49:59","modified_gmt":"2020-05-14T20:49:59","slug":"%e8%af%b7%e6%95%99-%e5%90%8c%e4%b8%80%e5%bc%a0%e8%a1%a8%e6%a0%b9%e6%8d%ae%e6%8c%87%e5%ae%9a-key-%e5%88%86%e7%bb%84%ef%bc%8c%e5%b9%b6%e6%89%a7%e8%a1%8c%e5%8f%8c%e9%87%8d%e7%bb%9f%e8%ae%a1","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=84919","title":{"rendered":"[\u8bf7\u6559] \u540c\u4e00\u5f20\u8868\u6839\u636e\u6307\u5b9a key \u5206\u7ec4\uff0c\u5e76\u6267\u884c\u53cc\u91cd\u7edf\u8ba1"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  [\u8bf7\u6559] \u540c\u4e00\u5f20\u8868\u6839\u636e\u6307\u5b9a key \u5206\u7ec4\uff0c\u5e76\u6267\u884c\u53cc\u91cd\u7edf\u8ba1               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jss <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h3>\u6839\u636e\u5546\u6237 ID \u5206\u7ec4\uff0c\u540c\u65f6\u7edf\u8ba1\u51fa<code>order_type = 1<\/code>\u6d88\u8d39\u91d1\u989d<code>money<\/code>\u548c<code>order_type = 2<\/code>\u63d0\u73b0\u91d1\u989d<code>money<\/code><\/h3>\n<h5>\u8868\u7ed3\u6784<\/h5>\n<pre><code>DROP TABLE IF EXISTS `store_money_record`; CREATE TABLE `store_money_record` (   `id` int(11) NOT NULL AUTO_INCREMENT,   `order_no` char(40) NOT NULL,   `store_id` int(11) NOT NULL DEFAULT '0',   `money` decimal(10,2) DEFAULT '0.00',   `content` char(60) NOT NULL,   `type` tinyint(1) NOT NULL DEFAULT '0',   `order_id` int(11) DEFAULT '0',   `order_type` tinyint(1) DEFAULT '0',   `create_time` int(11) DEFAULT NULL,   `update_time` int(11) DEFAULT NULL,   `delete_time` int(11) DEFAULT NULL,   PRIMARY KEY (`id`),   UNIQUE KEY `order_no` (`order_no`),   KEY `idx_delete_time` (`delete_time`),   KEY `idx_store_id` (`store_id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1524347\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : asAnotherJack <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             select store_id, sum(if(order_type=1,money,0)) as money1, sum(if(order_type=2,money,0)) as money2 from store_money_record group by store_id                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1524348\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : jss <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @asAnotherJack \u8c22\u8c22                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1524349\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : jss <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @asAnotherJack \u8fd8\u662f\u8fd9\u4e2a\u8868 \u6839\u636e\u5546\u6237 ID \u5206\u7ec4\uff0c\u540c\u65f6\u7edf\u8ba1\u51fa order_type = 1 \u6d88\u8d39\u6570\u91cf\u548c order_type = 2 \u63d0\u73b0\u6570\u91cf \u600e\u4e48\u5199\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1524350\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : asAnotherJack <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jss #3 \u6d88\u8d39\u6570\u91cf\u6307\u4ec0\u4e48\uff0c\u6b21\u6570\u5417\uff1f count(if(order_type = 1,1,null))                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1524351\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : jss <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @asAnotherJack \u6211\u6ca1\u67e5\u5230\u8fd9\u5757\u6587\u6863\uff0c\u4e00\u76f4\u641e\u4e0d\u641e\u61c2 sum(if(order_type=1,money,0)) \u4e2d if \u91cc\u7684\u53c2\u6570 \u542b\u4e49\uff1b \u90a3\u4e2a 0 \/null \u5728\u4ec0\u4e48\u4f7f\u7528\uff1f \u56e0\u4e3a\uff0c\u6211\u4e4b\u524d\u8fdb\u884c count(if(order_type = 1,1,0)) \u65f6\uff0c\u67e5\u8be2\u7ed3\u679c\u4e0d\u6b63\u786e \uff0c\u5c06 0 \u6539\u6210 null \u5c31\u5bf9\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1524352\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : asAnotherJack <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jss #5 \u641c count if sum if \u7f51\u4e0a\u6709\u5f88\u591a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1524353\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : jss <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @asAnotherJack \u8c22\u8c22                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>[\u8bf7\u6559] \u540c\u4e00\u5f20\u8868\u6839\u636e\u6307\u5b9a key&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/84919"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=84919"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/84919\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=84919"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=84919"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=84919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}