{"id":5554,"date":"2024-11-14T13:16:46","date_gmt":"2024-11-14T05:16:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5554\/"},"modified":"2024-11-14T13:16:46","modified_gmt":"2024-11-14T05:16:46","slug":"mysql%e6%9f%a5%e8%af%a2%e8%af%ad%e5%8f%a5%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5554\/","title":{"rendered":"mysql\u67e5\u8be2\u8bed\u53e5\u600e\u4e48\u5199"},"content":{"rendered":"<blockquote><p>\n  mysql \u67e5\u8be2\u8bed\u53e5\u7528\u4e8e\u4ece\u6570\u636e\u5e93\u68c0\u7d22\u6570\u636e\uff0c\u9075\u5faa\u7279\u5b9a\u8bed\u6cd5\uff1aselect \u5b50\u53e5\u6307\u5b9a\u8981\u68c0\u7d22\u7684\u5217\u3002from \u5b50\u53e5\u6307\u5b9a\u8981\u67e5\u8be2\u7684\u8868\u3002where \u5b50\u53e5\u7b5b\u9009\u6570\u636e\u3002group by \u5b50\u53e5\u5bf9\u6570\u636e\u5206\u7ec4\u3002order by \u5b50\u53e5\u5bf9\u7ed3\u679c\u6392\u5e8f\u3002limit \u5b50\u53e5\u9650\u5236\u8fd4\u56de\u7ed3\u679c\u6761\u6570\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/29\/2024052909422673556.jpg\" class=\"aligncenter\" title=\"mysql\u67e5\u8be2\u8bed\u53e5\u600e\u4e48\u5199\u63d2\u56fe\" alt=\"mysql\u67e5\u8be2\u8bed\u53e5\u600e\u4e48\u5199\u63d2\u56fe\" \/><\/p>\n<h2>MySQL \u67e5\u8be2\u8bed\u53e5\u7f16\u5199\u6307\u5357<\/h2>\n<p>MySQL \u67e5\u8be2\u8bed\u53e5\u7528\u4e8e\u4ece\u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u6240\u9700\u7684\u6570\u636e\u3002\u638c\u63e1\u6b63\u786e\u7684\u8bed\u6cd5\u548c\u7ed3\u6784\u81f3\u5173\u91cd\u8981\uff0c\u4ee5\u6709\u6548\u5730\u68c0\u7d22\u4fe1\u606f\u3002<\/p>\n<h3>\u67e5\u8be2\u8bed\u53e5\u7ed3\u6784<\/h3>\n<p>\u57fa\u672c\u67e5\u8be2\u8bed\u53e5\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<pre>SELECT \u5217\u540d1, \u5217\u540d2, ...\nFROM \u8868\u540d\n[WHERE \u6761\u4ef6]\n[GROUP BY \u5206\u7ec4\u4f9d\u636e]\n[ORDER BY \u6392\u5e8f\u4f9d\u636e]\n[LIMIT \u8fd4\u56de\u6761\u6570]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>SELECT * FROM customers WHERE age &gt; 25;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>SELECT \u5b50\u53e5<\/h3>\n<p>SELECT \u5b50\u53e5\u6307\u5b9a\u8981\u68c0\u7d22\u7684\u5217\u3002\u4f7f\u7528 * \u8868\u793a\u9009\u62e9\u6240\u6709\u5217\u3002<\/p>\n<h3>FROM \u5b50\u53e5<\/h3>\n<p>FROM \u5b50\u53e5\u6307\u5b9a\u8981\u67e5\u8be2\u7684\u8868\u3002<\/p>\n<h3>WHERE \u5b50\u53e5<\/h3>\n<p>WHERE \u5b50\u53e5\u6307\u5b9a\u8981\u7b5b\u9009\u6570\u636e\u7684\u6761\u4ef6\u3002\u6761\u4ef6\u53ef\u4ee5\u662f\u6bd4\u8f83\u3001\u903b\u8f91\u8fd0\u7b97\u7b26\u6216\u51fd\u6570\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>WHERE age &gt; 25 AND gender = 'male'<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>GROUP BY \u5b50\u53e5<\/h3>\n<p>GROUP BY \u5b50\u53e5\u5c06\u6570\u636e\u6309\u6307\u5b9a\u5217\u5206\u7ec4\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>GROUP BY age<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>ORDER BY \u5b50\u53e5<\/h3>\n<p>ORDER BY \u5b50\u53e5\u6309\u6307\u5b9a\u5217\u5bf9\u7ed3\u679c\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>ORDER BY age DESC<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>LIMIT \u5b50\u53e5<\/h3>\n<p>LIMIT \u5b50\u53e5\u9650\u5236\u8fd4\u56de\u7684\u7ed3\u679c\u6761\u6570\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>LIMIT 10<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>\u9644\u52a0\u6ce8\u610f\u4e8b\u9879<\/h3>\n<ul>\n<li> <strong>\u4f7f\u7528\u522b\u540d\uff1a<\/strong>\u53ef\u4ee5\u4f7f\u7528 AS \u4e3a\u5217\u6216\u8868\u6307\u5b9a\u522b\u540d\uff0c\u4ee5\u63d0\u9ad8\u53ef\u8bfb\u6027\u3002<\/li>\n<li> <strong>\u5355\u5f15\u53f7\u548c\u53cc\u5f15\u53f7\uff1a<\/strong>\u53ef\u4ee5\u7528\u5355\u5f15\u53f7\u6216\u53cc\u5f15\u53f7\u62ec\u8d77\u6765\u3002<\/li>\n<li> <strong>\u6ce8\u91ca\uff1a<\/strong>\u4f7f\u7528 &#8212; \u5f00\u59cb\u884c\u6ce8\u91ca\uff0c\u4f7f\u7528 \/* \u548c *\/ \u5f00\u59cb\u548c\u7ed3\u675f\u591a\u884c\u6ce8\u91ca\u3002<\/li>\n<li> <strong>\u5927\u5c0f\u5199\u654f\u611f\uff1a<\/strong>MySQL \u67e5\u8be2\u8bed\u53e5\u5927\u5c0f\u5199\u654f\u611f\u3002<\/li>\n<li> <strong>\u4f7f\u7528\u5f15\u53f7\uff1a<\/strong>\u5728\u67e5\u8be2\u4e2d\u4f7f\u7528\u5173\u952e\u5b57\u65f6\uff0c\u9700\u8981\u7528\u53cd\u5f15\u53f7\u62ec\u8d77\u6765\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u9075\u5faa\u8fd9\u4e9b\u6307\u5357\uff0c\u60a8\u53ef\u4ee5\u7f16\u5199\u6709\u6548\u7684 MySQL \u67e5\u8be2\u8bed\u53e5\uff0c\u4ece\u6570\u636e\u5e93\u4e2d\u51c6\u786e\u5730\u68c0\u7d22\u4fe1\u606f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u67e5\u8be2\u8bed\u53e5\u600e\u4e48\u5199\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>mysql \u67e5\u8be2\u8bed\u53e5\u7528\u4e8e\u4ece\u6570\u636e\u5e93\u68c0\u7d22\u6570\u636e\uff0c\u9075\u5faa\u7279\u5b9a\u8bed\u6cd5\uff1aselect \u5b50\u53e5\u6307\u5b9a\u8981\u68c0\u7d22\u7684\u5217\u3002from \u5b50\u53e5\u6307\u5b9a\u8981\u67e5\u8be2\u7684\u8868\u3002where \u5b50\u53e5\u7b5b\u9009\u6570\u636e\u3002group by \u5b50\u53e5\u5bf9\u6570\u636e\u5206\u7ec4\u3002order by \u5b50\u53e5\u5bf9\u7ed3\u679c\u6392\u5e8f\u3002limit \u5b50\u53e5\u9650\u5236\u8fd4\u56de\u7ed3\u679c\u6761\u6570\u3002 MySQL \u67e5\u8be2\u8bed\u53e5\u7f16\u5199\u6307\u5357 MySQL \u67e5\u8be2\u8bed\u53e5\u7528\u4e8e\u4ece\u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u6240\u9700\u7684\u6570\u636e\u3002\u638c\u63e1\u6b63\u786e\u7684\u8bed\u6cd5\u548c\u7ed3\u6784\u81f3\u5173\u91cd\u8981\uff0c\u4ee5\u6709\u6548\u5730\u68c0\u7d22\u4fe1\u606f\u3002 \u67e5\u8be2\u8bed\u53e5\u7ed3\u6784 \u57fa\u672c\u67e5\u8be2\u8bed\u53e5\u7ed3\u6784\u5982\u4e0b\uff1a SELECT \u5217\u540d1, \u5217\u540d2, &#8230; FROM \u8868\u540d [WHERE \u6761\u4ef6] [GROUP BY \u5206\u7ec4\u4f9d\u636e] [ORDER BY \u6392\u5e8f\u4f9d\u636e] [LIMIT \u8fd4\u56de\u6761\u6570] \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a SELECT * FROM customers WHERE age &gt; 25; \u767b\u5f55\u540e\u590d\u5236 SELECT \u5b50\u53e5 SELECT \u5b50\u53e5\u6307\u5b9a\u8981\u68c0\u7d22\u7684\u5217\u3002\u4f7f\u7528 * \u8868\u793a\u9009\u62e9\u6240\u6709\u5217\u3002 FROM \u5b50\u53e5 FROM \u5b50\u53e5\u6307\u5b9a\u8981\u67e5\u8be2\u7684\u8868\u3002 WHERE \u5b50\u53e5 [&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-5554","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5554","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=5554"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5554\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}