{"id":3055,"date":"2018-09-12T11:59:10","date_gmt":"2018-09-12T03:59:10","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3055"},"modified":"2018-09-12T11:59:10","modified_gmt":"2018-09-12T03:59:10","slug":"%e4%bd%a0%e7%9c%9f%e7%9a%84%e6%87%82-select-count-%e5%90%97%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3055","title":{"rendered":"\u4f60\u771f\u7684\u61c2 select count(*) \u5417\uff1f"},"content":{"rendered":"<p>\n\t\u5982\u9898\uff0c\u4f60\u771f\u7684\u61c2 select count(*) \u5417\uff1f\u5f88\u591a\u9762\u8bd5\u8005\u6216\u8005\u9ad8\u7ea7\u5f00\u53d1\u5de5\u7a0b\u5e08\u90fd\u4f1a\u8bf4\u4e0d\u8981\u7528 count(*)\uff0c\u8fd9\u6837\u5199\u67e5\u8be2\u4f1a\u6bd4\u8f83\u6162\u3002count(1) \u6bd4 count(*) \u5feb\uff0c\u8fd9\u6837\u8bf4\u771f\u7684\u5bf9\u5417\uff1f\u4e14\u542c\u672c\u6587\u6765\u8bb2\u89e3\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u8f83\u771f\u513f\uff01\n<\/p>\n<p>\n\t\u5728\u67d0\u4e9b\u65f6\u5019\uff0ccount(1) \u6bd4 count(*) \u7528\u65f6\u8fd8\u591a\u3002\u4f60\u778e\u8bf4\uff0c\u6b3a\u8d1f\u6211\u4e0d\u61c2\u662f\u5427\uff01\n<\/p>\n<p>\n\t\u5982\u679c\u6211\u544a\u8bc9\u4f60 MyISAM \u4f1a\u76f4\u63a5\u5b58\u50a8\u603b\u884c\u6570\uff0cInnoDB \u5219\u4e0d\u4f1a\uff0c\u9700\u8981\u6309\u884c\u626b\u63cf\u3002\u5f53\u67e5\u8be2\u6761\u4ef6\u4e3a\u5168\u8868\u65f6\uff0c\u5373\u6ca1\u6709 where \u6761\u4ef6\u65f6\uff0cMyISAM \u4f1a\u77ac\u95f4\u8fd4\u56de\u3002\n<\/p>\n<p>\n\t\u4e5f\u5c31\u662f\u8bf4\uff1a\u5bf9\u4e8e select count(*) from xttblog; \u5982\u679c\u6570\u636e\u91cf\u5927\uff0cMyISAM \u4f1a\u77ac\u95f4\u8fd4\u56de\uff0c\u800c InnoDB \u5219\u4f1a\u4e00\u884c\u884c\u626b\u63cf\u3002\u7279\u522b\u662f\u5927\u6570\u636e\u91cf\u7684\u8868\uff0cInnoDB \u4e0d\u8981\u8f7b\u6613 select count(*)\uff0c\u6027\u80fd\u6d88\u8017\u6781\u5927\u3002\n<\/p>\n<p>\n\t\u53ea\u6709\u67e5\u8be2\u5168\u8868\u7684\u603b\u884c\u6570\uff0cMyISAM \u624d\u4f1a\u76f4\u63a5\u8fd4\u56de\u7ed3\u679c\uff0c\u5f53\u52a0\u4e86 where \u6761\u4ef6\u540e\uff0c\u4e24\u79cd\u5b58\u50a8\u5f15\u64ce\u7684\u5904\u7406\u65b9\u5f0f\u7c7b\u4f3c\u3002\n<\/p>\n<p>\n\t\u4f8b\u5982\uff1a\n<\/p>\n<pre class=\"brush:sql;\">\r\nxttblog(id, name, url, text, keyword);<\/pre>\n<p>\n\tid \u4e3a PK\n<\/p>\n<p>\n\tkeyword \u6709 index\n<\/p>\n<p>\n\t\u6267\u884c\u4e0b\u9762\u7684 SQL \u8bed\u53e5\uff1a\n<\/p>\n<pre class=\"brush:sql;\">\r\nselect count(*) xttblog where keyword = &#039;java&#039; and name = &#039;\u4e1a\u4f59\u8349&#039;;<\/pre>\n<p>\n\t\u8fd9\u65f6\uff0c\u9488\u5bf9\u4e0a\u9762\u8fd9\u6761\u67e5\u8be2\u8bed\u53e5\uff0c\u4e24\u79cd\u5b58\u50a8\u5f15\u64ce\u7684\u5904\u7406\u65b9\u5f0f\u7c7b\u4f3c\uff0c\u90fd\u9700\u8981\u8fdb\u884c\u7d22\u5f15\u626b\u63cf\u3002\n<\/p>\n<p>\n\t\u4f46\u662f\u4e0d\u7ba1\u54ea\u79cd\u5b58\u50a8\u5f15\u64ce\uff0c\u90fd\u8981\u5efa\u7acb\u597d\u7d22\u5f15\u3002\n<\/p>\n<p>\n\tcount(1) \u867d\u7136\u5728\u67e5\u8be2\u7ed3\u679c\u4e0a\u7b49\u4ef7\u4e8e count(*)\uff0c\u4f46\u662f\u5728\u67d0\u4e9b\u65f6\u5019\uff0c\u67e5\u8be2\u65f6\u95f4\u5374\u80fd\u5237\u65b0\u4f60\u7684\u4e09\u89c2\u3002\n<\/p>\n<p>\n\t\u4e0b\u9762\u6211\u4eec\u8bf4\u8bf4 count(*)\u3001count(1)\u3001count(\u5217\u540d)\u4e09\u8005\u7684\u533a\u522b\uff1a\n<\/p>\n<ul>\n<li>\n\t\tcount(*)\u5305\u62ec\u4e86\u6240\u6709\u7684\u5217\uff0c\u76f8\u5f53\u4e8e\u884c\u6570\uff0c\u5728\u7edf\u8ba1\u7ed3\u679c\u7684\u65f6\u5019\uff0c\u4e0d\u4f1a\u5ffd\u7565\u5217\u503c\u4e3aNULL &nbsp;\n\t<\/li>\n<li>\n\t\tcount(1)\u5305\u62ec\u4e86\u5ffd\u7565\u6240\u6709\u5217\uff0c\u75281\u4ee3\u8868\u4ee3\u7801\u884c\uff0c\u5728\u7edf\u8ba1\u7ed3\u679c\u7684\u65f6\u5019\uff0c\u4e0d\u4f1a\u5ffd\u7565\u5217\u503c\u4e3aNULL &nbsp;\n\t<\/li>\n<li>\n\t\tcount(\u5217\u540d)\u53ea\u5305\u62ec\u5217\u540d\u90a3\u4e00\u5217\uff0c\u5728\u7edf\u8ba1\u7ed3\u679c\u7684\u65f6\u5019\uff0c\u4f1a\u5ffd\u7565\u5217\u503c\u4e3a\u7a7a\uff08\u8fd9\u91cc\u7684\u7a7a\u4e0d\u662f\u53ea\u7a7a\u5b57\u7b26\u4e32\u6216\u80050\uff0c\u800c\u662f\u8868\u793anull\uff09\u7684\u8ba1\u6570\uff0c\u5373\u67d0\u4e2a\u5b57\u6bb5\u503c\u4e3aNULL\u65f6\uff0c\u4e0d\u7edf\u8ba1\u3002\n\t<\/li>\n<\/ul>\n<p>\n\t\u5bf9\u4e8e InnoDB \u6765\u8bf4\uff0c\u5f53\u5217\u540d\u4e3a\u4e3b\u952e\uff0ccount(\u5217\u540d) \u4f1a\u6bd4 count(1) \u5feb\uff1b\u5f53\u5217\u540d\u4e0d\u4e3a\u4e3b\u952e\uff0ccount(1) \u4f1a\u6bd4 count(\u5217\u540d) \u5feb\uff1b\u5982\u679c\u8868\u591a\u4e2a\u5217\u5e76\u4e14\u6ca1\u6709\u4e3b\u952e\uff0c\u5219 count\uff081\uff09\u7684\u6267\u884c\u6548\u7387\u4f18\u4e8e count\uff08*)\uff1b\u5982\u679c\u6709\u4e3b\u952e\uff0c\u5219 select count\uff08\u4e3b\u952e\uff09\u7684\u6267\u884c\u6548\u7387\u662f\u6700\u4f18\u7684\uff1b\u5982\u679c\u8868\u53ea\u6709\u4e00\u4e2a\u5b57\u6bb5\uff0c\u5219 select count\uff08*\uff09\u6700\u4f18\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3055\">\u4f60\u771f\u7684\u61c2 select count(*) \u5417\uff1f<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5982\u9898\uff0c\u4f60\u771f\u7684\u61c2 select count(*) \u5417\uff1f\u5f88\u591a\u9762\u8bd5\u8005\u6216\u8005\u9ad8\u7ea7\u5f00\u53d1\u5de5\u7a0b\u5e08\u90fd\u4f1a\u8bf4\u4e0d\u8981\u7528 count(*) [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,6],"tags":[1674,1675,580,155,156],"class_list":["post-3055","post","type-post","status-publish","format-standard","hentry","category-sql","category-yyzt","tag-innodb","tag-myisam","tag-mysql----dba","tag-sql","tag-156"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3055"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3055\/revisions"}],"predecessor-version":[{"id":3056,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3055\/revisions\/3056"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}