{"id":7968,"date":"2024-11-14T08:54:03","date_gmt":"2024-11-14T00:54:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7968\/"},"modified":"2024-11-14T08:54:03","modified_gmt":"2024-11-14T00:54:03","slug":"%e7%bb%9f%e8%ae%a129%e4%b8%87%e6%9d%a1%e6%95%b0%e6%8d%ae%e8%80%97%e6%97%b613%e7%a7%92%ef%bc%8c%e5%90%88%e7%90%86%e5%90%97%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7968\/","title":{"rendered":"\u7edf\u8ba129\u4e07\u6761\u6570\u636e\u8017\u65f613\u79d2\uff0c\u5408\u7406\u5417\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173138511775056.jpg\" class=\"aligncenter\" title=\"\u7edf\u8ba129\u4e07\u6761\u6570\u636e\u8017\u65f613\u79d2\uff0c\u5408\u7406\u5417\uff1f\u63d2\u56fe\" alt=\"\u7edf\u8ba129\u4e07\u6761\u6570\u636e\u8017\u65f613\u79d2\uff0c\u5408\u7406\u5417\uff1f\u63d2\u56fe\" \/><\/p>\n<h2>\u7edf\u8ba129\u4e07\u6761\u6570\u636e\u8017\u65f613\u79d2\uff0c\u662f\u5426\u5408\u7406\uff1f<\/h2>\n<p><strong>\u95ee\u9898:<\/strong><\/p>\n<p>\u6267\u884c\u5982\u4e0bsql\u67e5\u8be2\u65f6\uff0c\u8017\u65f613\u79d2\uff0c\u67e5\u8be229\u4e07\u6761\u6570\u636e\u3002<\/p>\n<pre>select count(*) from `t_order_old`<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u89e3\u7b54:<\/strong><\/p>\n<p>\u76f4\u63a5\u4f7f\u7528count(*)\u7edf\u8ba1\u6570\u636e\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6027\u80fd\u95ee\u9898\u3002\u5c24\u5176\u662f\u5728\u6570\u636e\u91cf\u8f83\u5927\u65f6\uff0c\u6bcf\u6b21\u67e5\u8be2\u90fd\u9700\u8981\u904d\u5386\u6240\u6709\u6570\u636e\u8fdb\u884c\u7edf\u8ba1\u3002<\/p>\n<p><strong>\u4f18\u5316\u5efa\u8bae:<\/strong><\/p>\n<p>\u907f\u514d\u4f7f\u7528count(*)\uff0c\u8f6c\u800c\u5c06\u9700\u8981\u7684\u7edf\u8ba1\u7ed3\u679c\u5355\u72ec\u5b58\u50a8\u3002<\/p>\n<ul>\n<li> <strong>\u4f7f\u7528\u89e6\u53d1\u5668:<\/strong><br \/>\u5728\u66f4\u65b0\u6570\u636e\u65f6\u81ea\u52a8\u66f4\u65b0\u7edf\u8ba1\u6570\u636e\u3002<\/li>\n<li> <strong>\u81ea\u884c\u7ef4\u62a4\u7edf\u8ba1\u6570\u636e:<\/strong><br \/>\u5728\u4e1a\u52a1\u903b\u8f91\u4e2d\u540c\u6b65\u7ef4\u62a4\u7edf\u8ba1\u6570\u636e\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b:<\/strong><\/p>\n<p>\u4ee5\u6587\u7ae0\u56de\u590d\u6570\u91cf\u4e3a\u4f8b\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u65b9\u5f0f\u7edf\u8ba1:<\/p>\n<pre>-- \u4e3b\u8868\nCREATE TABLE `t_article` (\n  `article_id` INT NOT NULL AUTO_INCREMENT,\n  `reply_count` INT NOT NULL DEFAULT 0,\n  \n  PRIMARY KEY (`article_id`)\n);\n\n\n-- \u89e6\u53d1\u5668\uff1a\u66f4\u65b0\u56de\u590d\u6570\u91cf\nCREATE TRIGGER `tr_article_update_reply_count` AFTER UPDATE ON `t_reply`\nFOR EACH ROW\nBEGIN\n  UPDATE `t_article` SET `reply_count` = `reply_count` + NEW.`status` - OLD.`status`\n  WHERE `article_id` = NEW.`article_id`;\nEND;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u6837\uff0c\u6bcf\u6b21\u66f4\u65b0\u56de\u590d\u6570\u636e\u65f6\uff0c\u6587\u7ae0\u7684\u56de\u590d\u6570\u91cf\u4f1a\u81ea\u52a8\u66f4\u65b0\uff0c\u4ece\u800c\u907f\u514d\u4f7f\u7528count(*)\u9891\u7e41\u7edf\u8ba1\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u7edf\u8ba129\u4e07\u6761\u6570\u636e\u8017\u65f613\u79d2\uff0c\u5408\u7406\u5417\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7edf\u8ba129\u4e07\u6761\u6570\u636e\u8017\u65f613\u79d2\uff0c\u662f\u5426\u5408\u7406\uff1f \u95ee\u9898: \u6267\u884c\u5982\u4e0bsql\u67e5\u8be2\u65f6\uff0c\u8017\u65f613\u79d2\uff0c\u67e5\u8be229\u4e07\u6761\u6570\u636e\u3002 select count(*) from `t_order_old` \u767b\u5f55\u540e\u590d\u5236 \u89e3\u7b54: \u76f4\u63a5\u4f7f\u7528count(*)\u7edf\u8ba1\u6570\u636e\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6027\u80fd\u95ee\u9898\u3002\u5c24\u5176\u662f\u5728\u6570\u636e\u91cf\u8f83\u5927\u65f6\uff0c\u6bcf\u6b21\u67e5\u8be2\u90fd\u9700\u8981\u904d\u5386\u6240\u6709\u6570\u636e\u8fdb\u884c\u7edf\u8ba1\u3002 \u4f18\u5316\u5efa\u8bae: \u907f\u514d\u4f7f\u7528count(*)\uff0c\u8f6c\u800c\u5c06\u9700\u8981\u7684\u7edf\u8ba1\u7ed3\u679c\u5355\u72ec\u5b58\u50a8\u3002 \u4f7f\u7528\u89e6\u53d1\u5668:\u5728\u66f4\u65b0\u6570\u636e\u65f6\u81ea\u52a8\u66f4\u65b0\u7edf\u8ba1\u6570\u636e\u3002 \u81ea\u884c\u7ef4\u62a4\u7edf\u8ba1\u6570\u636e:\u5728\u4e1a\u52a1\u903b\u8f91\u4e2d\u540c\u6b65\u7ef4\u62a4\u7edf\u8ba1\u6570\u636e\u3002 \u793a\u4f8b: \u4ee5\u6587\u7ae0\u56de\u590d\u6570\u91cf\u4e3a\u4f8b\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u65b9\u5f0f\u7edf\u8ba1: &#8212; \u4e3b\u8868 CREATE TABLE `t_article` ( `article_id` INT NOT NULL AUTO_INCREMENT, `reply_count` INT NOT NULL DEFAULT 0, PRIMARY KEY (`article_id`) ); &#8212; \u89e6\u53d1\u5668\uff1a\u66f4\u65b0\u56de\u590d\u6570\u91cf CREATE TRIGGER `tr_article_update_reply_count` AFTER UPDATE ON `t_reply` FOR EACH ROW BEGIN UPDATE `t_article` SET `reply_count` = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7968","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7968","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=7968"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7968\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}