{"id":6363,"date":"2024-11-14T12:05:49","date_gmt":"2024-11-14T04:05:49","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6363\/"},"modified":"2024-11-14T12:05:49","modified_gmt":"2024-11-14T04:05:49","slug":"mysql%e5%bf%85%e8%83%8c%e6%9f%a5%e8%af%a2%e8%af%ad%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6363\/","title":{"rendered":"mysql\u5fc5\u80cc\u67e5\u8be2\u8bed\u53e5"},"content":{"rendered":"<blockquote><p>\n  mysql \u67e5\u8be2\u5fc5\u77e5\uff1a1. \u67e5\u8be2\u6240\u6709\u6570\u636e\uff1aselect * from table_name; 2. \u67e5\u8be2\u7279\u5b9a\u5217\u6570\u636e\uff1aselect column1, column2, &#8230; from table_name; 3. \u6761\u4ef6\u67e5\u8be2\uff1aselect &#8230; from table_name where condition; 4. \u6392\u5e8f\u67e5\u8be2\uff1aselect &#8230; from table_name order by column_name asc\/desc; 5. \u5206\u9875\u67e5\u8be2\uff1aselect &#8230; from tabl\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/01\/2024080103011379701.jpg\" class=\"aligncenter\" title=\"mysql\u5fc5\u80cc\u67e5\u8be2\u8bed\u53e5\u63d2\u56fe\" alt=\"mysql\u5fc5\u80cc\u67e5\u8be2\u8bed\u53e5\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u5fc5\u80cc\u67e5\u8be2\u8bed\u53e5<\/strong><\/p>\n<p><strong>1. \u67e5\u8be2\u6240\u6709\u6570\u636e<\/strong><\/p>\n<p>SELECT * FROM table_name;<\/p>\n<p><strong>2. \u67e5\u8be2\u7279\u5b9a\u5217\u7684\u6570\u636e<\/strong><\/p>\n<p>SELECT column1, column2, &#8230; FROM table_name;<\/p>\n<p><strong>3. \u6839\u636e\u6761\u4ef6\u67e5\u8be2\u6570\u636e<\/strong><\/p>\n<p>SELECT column1, column2, &#8230; FROM table_name WHERE condition;<br \/>\u4f8b\u5982\uff1aSELECT * FROM students WHERE name = &#8216;John&#8217;;<\/p>\n<p><strong>4. \u6392\u5e8f\u67e5\u8be2\u7ed3\u679c<\/strong><\/p>\n<p>SELECT column1, column2, &#8230; FROM table_name ORDER BY column_name ASC\/DESC;<br \/>\u4f8b\u5982\uff1aSELECT * FROM students ORDER BY name DESC;<\/p>\n<p><strong>5. \u5206\u9875\u67e5\u8be2<\/strong><\/p>\n<p>SELECT column1, column2, &#8230; FROM table_name LIMIT offset, limit;<br \/>\u4f8b\u5982\uff1aSELECT * FROM students LIMIT 10, 20;\uff08\u67e5\u8be2\u7b2c11\u523030\u6761\u8bb0\u5f55\uff09<\/p>\n<p><strong>6. <\/strong><\/p>\n<ul>\n<li>COUNT()\uff1a\u8ba1\u7b97\u884c\u6570<\/li>\n<li>SUM()\uff1a\u6c42\u548c<\/li>\n<li>AVG()\uff1a\u6c42\u5e73\u5747\u503c<\/li>\n<li>MIN()\uff1a\u6c42\u6700\u5c0f\u503c<\/li>\n<li>MAX()\uff1a\u6c42\u6700\u5927\u503c<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff1aSELECT COUNT(*) FROM students;\uff08\u8ba1\u7b97\u5b66\u751f\u8868\u4e2d\u7684\u8bb0\u5f55\u6570\uff09<\/p>\n<p><strong>7. \u5206\u7ec4\u67e5\u8be2<\/strong><\/p>\n<p>SELECT column1, column2, &#8230; FROM table_name GROUP BY column_name;<br \/>\u4f8b\u5982\uff1aSELECT course_name, COUNT(*) AS student_count FROM students GROUP BY course_name;\uff08\u6309\u8bfe\u7a0b\u540d\u79f0\u5206\u7ec4\uff0c\u7edf\u8ba1\u6bcf\u95e8\u8bfe\u7a0b\u7684\u5b66\u751f\u6570\uff09<\/p>\n<p><strong>8. \u8054\u5408\u67e5\u8be2<\/strong><\/p>\n<ul>\n<li>UNION\uff1a\u5408\u5e76\u67e5\u8be2\u7ed3\u679c<\/li>\n<li>UNION ALL\uff1a\u5408\u5e76\u67e5\u8be2\u7ed3\u679c\uff0c\u5305\u62ec\u91cd\u590d\u884c<\/li>\n<li>INTERSECT\uff1a\u83b7\u53d6\u4e24\u4e2a\u67e5\u8be2\u7ed3\u679c\u7684\u4ea4\u96c6<\/li>\n<li>EXCEPT\uff1a\u83b7\u53d6\u4e24\u4e2a\u67e5\u8be2\u7ed3\u679c\u7684\u5dee\u96c6<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff1aSELECT * FROM students UNION SELECT * FROM teachers;\uff08\u5408\u5e76\u5b66\u751f\u8868\u548c\u8001\u5e08\u8868\u7684\u6570\u636e\uff09<\/p>\n<p><strong>9. \u5b50\u67e5\u8be2<\/strong><\/p>\n<p>\u5728\u4e3b\u67e5\u8be2\u4e2d\u5d4c\u5957\u4e00\u4e2a\u67e5\u8be2\uff0c\u79f0\u4e3a\u5b50\u67e5\u8be2\u3002<\/p>\n<p><strong>10. JOIN \u67e5\u8be2<\/strong><\/p>\n<p>JOIN \u7528\u4e8e\u5c06\u591a\u4e2a\u8868\u4e2d\u7684\u6570\u636e\u5173\u8054\u8d77\u6765\u3002<\/p>\n<ul>\n<li>INNER JOIN\uff1a\u8fd4\u56de\u4e24\u4e2a\u8868\u4e2d\u5177\u6709\u5339\u914d\u503c\u7684\u8bb0\u5f55<\/li>\n<li>LEFT JOIN\uff1a\u8fd4\u56de\u5de6\u8868\u7684\u6240\u6709\u8bb0\u5f55\uff0c\u4ee5\u53ca\u4e0e\u53f3\u8868\u5339\u914d\u7684\u8bb0\u5f55<\/li>\n<li>RIGHT JOIN\uff1a\u8fd4\u56de\u53f3\u8868\u7684\u6240\u6709\u8bb0\u5f55\uff0c\u4ee5\u53ca\u4e0e\u5de6\u8868\u5339\u914d\u7684\u8bb0\u5f55<\/li>\n<li>FULL JOIN\uff1a\u8fd4\u56de\u4e24\u4e2a\u8868\u7684\u6240\u6709\u8bb0\u5f55\uff0c\u4ee5\u53ca\u5339\u914d\u548c\u4e0d\u5339\u914d\u7684\u8bb0\u5f55<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fc5\u80cc\u67e5\u8be2\u8bed\u53e5\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\u5fc5\u77e5\uff1a1. \u67e5\u8be2\u6240\u6709\u6570\u636e\uff1aselect * from table_name; 2. \u67e5\u8be2\u7279\u5b9a\u5217\u6570\u636e\uff1aselect column1, column2, &#8230; from table_name; 3. \u6761\u4ef6\u67e5\u8be2\uff1aselect &#8230; from table_name where condition; 4. \u6392\u5e8f\u67e5\u8be2\uff1aselect &#8230; from table_name order by column_name asc\/desc; 5. \u5206\u9875\u67e5\u8be2\uff1aselect &#8230; from tabl MySQL \u5fc5\u80cc\u67e5\u8be2\u8bed\u53e5 1. \u67e5\u8be2\u6240\u6709\u6570\u636e SELECT * FROM table_name; 2. \u67e5\u8be2\u7279\u5b9a\u5217\u7684\u6570\u636e SELECT column1, column2, &#8230; FROM table_name; 3. \u6839\u636e\u6761\u4ef6\u67e5\u8be2\u6570\u636e SELECT column1, column2, [&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-6363","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6363","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=6363"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6363\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}