{"id":5145,"date":"2024-11-14T11:27:51","date_gmt":"2024-11-14T03:27:51","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5145\/"},"modified":"2024-11-14T11:27:51","modified_gmt":"2024-11-14T03:27:51","slug":"mysql%e6%9f%a5%e8%af%a2%e8%af%ad%e6%b3%95%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5145\/","title":{"rendered":"mysql\u67e5\u8be2\u8bed\u6cd5\u600e\u4e48\u5199"},"content":{"rendered":"<blockquote><p>\n  mysql\u67e5\u8be2\u8bed\u6cd5\u7528\u4e8e\u4ece\u6570\u636e\u5e93\u4e2d\u68c0\u7d22\u6570\u636e\uff0c\u5305\u62ec\uff1aselect\u5173\u952e\u5b57\u3001\u5217\u540d\u3001from\u5173\u952e\u5b57\u3001where\u5b50\u53e5\u548corder by\u5b50\u53e5\u3002where\u5b50\u53e5\u4f7f\u7528\u8fd0\u7b97\u7b26\u8fc7\u6ee4\u7ed3\u679c\uff0c\u800corder by\u5b50\u53e5\u4f7f\u7528\u5173\u952e\u5b57asc\u6216desc\u5bf9\u7ed3\u679c\u6309\u5347\u5e8f\u6216\u964d\u5e8f\u6392\u5e8f\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/22\/2024052216453182736.jpg\" class=\"aligncenter\" title=\"mysql\u67e5\u8be2\u8bed\u6cd5\u600e\u4e48\u5199\u63d2\u56fe\" alt=\"mysql\u67e5\u8be2\u8bed\u6cd5\u600e\u4e48\u5199\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u67e5\u8be2\u8bed\u6cd5<\/strong><\/p>\n<p>MySQL \u7684\u67e5\u8be2\u8bed\u6cd5\u662f\u7528\u4e8e\u4ece\u6570\u636e\u5e93\u4e2d\u68c0\u7d22\u6570\u636e\u7684\u547d\u4ee4\u3002\u5b83\u7531\u4ee5\u4e0b\u90e8\u5206\u7ec4\u6210\uff1a<\/p>\n<ul>\n<li> <strong>SELECT \u5173\u952e\u5b57\uff1a<\/strong>\u8868\u793a\u8981\u67e5\u8be2\u7684\u6570\u636e\u3002<\/li>\n<li> <strong>\u5217\u540d\uff1a<\/strong>\u6307\u5b9a\u8981\u4ece\u8868\u4e2d\u68c0\u7d22\u54ea\u4e9b\u5217\u3002<\/li>\n<li> <strong>FROM \u5173\u952e\u5b57\uff1a<\/strong>\u6307\u5b9a\u8981\u5728\u5176\u4e2d\u6267\u884c\u67e5\u8be2\u7684\u8868\u3002<\/li>\n<li> <strong>WHERE \u5b50\u53e5\uff1a<\/strong>\uff08\u53ef\u9009\uff09\u6307\u5b9a\u6761\u4ef6\u4ee5\u8fc7\u6ee4\u67e5\u8be2\u7ed3\u679c\u3002<\/li>\n<li> <strong>ORDER BY \u5b50\u53e5\uff1a<\/strong>\uff08\u53ef\u9009\uff09\u6307\u5b9a\u7528\u4e8e\u5bf9\u7ed3\u679c\u8fdb\u884c\u6392\u5e8f\u7684\u5217\u3002<\/li>\n<\/ul>\n<p><strong>\u57fa\u672c\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>SELECT column_1, column_2, ..., column_n\nFROM table_name\nWHERE condition\nORDER BY column_name<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u67e5\u627e\u8868 &#8220;employees&#8221; \u4e2d\u6240\u6709\u540d\u4e3a &#8220;John&#8221; \u7684\u5458\u5de5\u7684\u4fe1\u606f\uff1a<\/p>\n<pre>SELECT *\nFROM employees\nWHERE first_name = \"John\";<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>WHERE \u5b50\u53e5<\/strong><\/p>\n<p>WHERE \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a\u8fc7\u6ee4\u67e5\u8be2\u7ed3\u679c\u7684\u6761\u4ef6\u3002\u5b83\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8fd0\u7b97\u7b26\uff1a<\/p>\n<ul>\n<li>\u7b49\u4e8e (=)<\/li>\n<li>\u4e0d\u7b49\u4e8e ( \u6216 !=)<\/li>\n<li>\u5927\u4e8e (&gt;)<\/li>\n<li>\u5c0f\u4e8e (<\/li>\n<li>\u5927\u4e8e\u6216\u7b49\u4e8e (&gt;=)<\/li>\n<li>\u5c0f\u4e8e\u6216\u7b49\u4e8e (<\/li>\n<\/ul>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre>SELECT *\nFROM employees\nWHERE salary &gt; 50000;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>ORDER BY \u5b50\u53e5<\/strong><\/p>\n<p>ORDER BY \u5b50\u53e5\u7528\u4e8e\u5bf9\u67e5\u8be2\u7ed3\u679c\u8fdb\u884c\u6392\u5e8f\u3002\u5b83\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u5173\u952e\u5b57\uff1a<\/p>\n<ul>\n<li>ASC\uff1a\u6309\u5347\u5e8f\u6392\u5e8f\uff08\u4ece\u5c0f\u5230\u5927\uff09<\/li>\n<li>DESC\uff1a\u6309\u964d\u5e8f\u6392\u5e8f\uff08\u4ece\u5927\u5230\u5c0f\uff09<\/li>\n<\/ul>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre>SELECT *\nFROM employees\nORDER BY last_name ASC;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u67e5\u8be2\u8bed\u6cd5\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\u6cd5\u7528\u4e8e\u4ece\u6570\u636e\u5e93\u4e2d\u68c0\u7d22\u6570\u636e\uff0c\u5305\u62ec\uff1aselect\u5173\u952e\u5b57\u3001\u5217\u540d\u3001from\u5173\u952e\u5b57\u3001where\u5b50\u53e5\u548corder by\u5b50\u53e5\u3002where\u5b50\u53e5\u4f7f\u7528\u8fd0\u7b97\u7b26\u8fc7\u6ee4\u7ed3\u679c\uff0c\u800corder by\u5b50\u53e5\u4f7f\u7528\u5173\u952e\u5b57asc\u6216desc\u5bf9\u7ed3\u679c\u6309\u5347\u5e8f\u6216\u964d\u5e8f\u6392\u5e8f\u3002 MySQL \u67e5\u8be2\u8bed\u6cd5 MySQL \u7684\u67e5\u8be2\u8bed\u6cd5\u662f\u7528\u4e8e\u4ece\u6570\u636e\u5e93\u4e2d\u68c0\u7d22\u6570\u636e\u7684\u547d\u4ee4\u3002\u5b83\u7531\u4ee5\u4e0b\u90e8\u5206\u7ec4\u6210\uff1a SELECT \u5173\u952e\u5b57\uff1a\u8868\u793a\u8981\u67e5\u8be2\u7684\u6570\u636e\u3002 \u5217\u540d\uff1a\u6307\u5b9a\u8981\u4ece\u8868\u4e2d\u68c0\u7d22\u54ea\u4e9b\u5217\u3002 FROM \u5173\u952e\u5b57\uff1a\u6307\u5b9a\u8981\u5728\u5176\u4e2d\u6267\u884c\u67e5\u8be2\u7684\u8868\u3002 WHERE \u5b50\u53e5\uff1a\uff08\u53ef\u9009\uff09\u6307\u5b9a\u6761\u4ef6\u4ee5\u8fc7\u6ee4\u67e5\u8be2\u7ed3\u679c\u3002 ORDER BY \u5b50\u53e5\uff1a\uff08\u53ef\u9009\uff09\u6307\u5b9a\u7528\u4e8e\u5bf9\u7ed3\u679c\u8fdb\u884c\u6392\u5e8f\u7684\u5217\u3002 \u57fa\u672c\u8bed\u6cd5\uff1a SELECT column_1, column_2, &#8230;, column_n FROM table_name WHERE condition ORDER BY column_name \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a \u67e5\u627e\u8868 &#8220;employees&#8221; \u4e2d\u6240\u6709\u540d\u4e3a &#8220;John&#8221; \u7684\u5458\u5de5\u7684\u4fe1\u606f\uff1a SELECT * FROM employees WHERE first_name = &#8220;John&#8221;; \u767b\u5f55\u540e\u590d\u5236 WHERE \u5b50\u53e5 WHERE \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a\u8fc7\u6ee4\u67e5\u8be2\u7ed3\u679c\u7684\u6761\u4ef6\u3002\u5b83\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8fd0\u7b97\u7b26\uff1a \u7b49\u4e8e (=) \u4e0d\u7b49\u4e8e ( \u6216 [&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-5145","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5145","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=5145"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5145\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}