{"id":76031,"date":"2026-02-13T19:57:26","date_gmt":"2026-02-13T11:57:26","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/76031.html"},"modified":"2026-02-13T19:57:26","modified_gmt":"2026-02-13T11:57:26","slug":"sql%e8%af%ad%e5%8f%a5%e4%bb%8e%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%9a%e5%8f%aa%e7%9c%8b%e8%bf%99%e4%b8%80%e7%af%87%e5%b0%b1%e5%a4%9f%e4%ba%86%ef%bc%81","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/76031.html","title":{"rendered":"SQL\u8bed\u53e5\u4ece\u5165\u95e8\u5230\u7cbe\u901a\uff1a\u53ea\u770b\u8fd9\u4e00\u7bc7\u5c31\u591f\u4e86\uff01"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"1.%20%E4%BB%80%E4%B9%88%E6%98%AF%20SQL-toc\" style=\"margin-left:80px\">1. \u4ec0\u4e48\u662f SQL<\/p>\n<p id=\"2.%20%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87%EF%BC%88%E6%96%B0%E6%89%8B%E6%8E%A8%E8%8D%90%EF%BC%89-toc\" style=\"margin-left:80px\">2. \u73af\u5883\u51c6\u5907&#xff08;\u65b0\u624b\u63a8\u8350&#xff09;<\/p>\n<p id=\"%E4%BA%8C%E3%80%81SQL%20%E5%85%A5%E9%97%A8%EF%BC%9A%E6%A0%B8%E5%BF%83%E8%AF%AD%E6%B3%95%EF%BC%88CRUD%EF%BC%89-toc\" style=\"margin-left:40px\">\u4e8c\u3001SQL \u5165\u95e8&#xff1a;\u6838\u5fc3\u8bed\u6cd5&#xff08;CRUD&#xff09;<\/p>\n<p id=\"1.%20%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%8E%E8%A1%A8%E6%93%8D%E4%BD%9C%EF%BC%88DDL%EF%BC%89-toc\" style=\"margin-left:80px\">1. \u6570\u636e\u5e93\u4e0e\u8868\u64cd\u4f5c&#xff08;DDL&#xff09;<\/p>\n<p id=\"2.%20%E6%95%B0%E6%8D%AE%E6%93%8D%E4%BD%9C%EF%BC%88DML%EF%BC%89%EF%BC%9A%E5%A2%9E%E5%88%A0%E6%94%B9-toc\" style=\"margin-left:80px\">2. \u6570\u636e\u64cd\u4f5c&#xff08;DML&#xff09;&#xff1a;\u589e\u5220\u6539<\/p>\n<p id=\"3.%20%E6%95%B0%E6%8D%AE%E6%9F%A5%E8%AF%A2%EF%BC%88DQL%EF%BC%89%EF%BC%9A%E6%9C%80%E6%A0%B8%E5%BF%83%E7%9A%84%20SELECT-toc\" style=\"margin-left:80px\">3. \u6570\u636e\u67e5\u8be2&#xff08;DQL&#xff09;&#xff1a;\u6700\u6838\u5fc3\u7684 SELECT<\/p>\n<p id=\"%EF%BC%881%EF%BC%89%E5%9F%BA%E7%A1%80%E6%9F%A5%E8%AF%A2-toc\" style=\"margin-left:120px\">&#xff08;1&#xff09;\u57fa\u7840\u67e5\u8be2<\/p>\n<p id=\"%EF%BC%882%EF%BC%89%E6%9D%A1%E4%BB%B6%E6%9F%A5%E8%AF%A2%EF%BC%88WHERE%EF%BC%89-toc\" style=\"margin-left:120px\">&#xff08;2&#xff09;\u6761\u4ef6\u67e5\u8be2&#xff08;WHERE&#xff09;<\/p>\n<p id=\"%EF%BC%883%EF%BC%89%E6%8E%92%E5%BA%8F%EF%BC%88ORDER%20BY%EF%BC%89-toc\" style=\"margin-left:120px\">&#xff08;3&#xff09;\u6392\u5e8f&#xff08;ORDER BY&#xff09;<\/p>\n<p id=\"%EF%BC%884%EF%BC%89%E8%81%9A%E5%90%88%E5%87%BD%E6%95%B0-toc\" style=\"margin-left:120px\">&#xff08;4&#xff09;\u805a\u5408\u51fd\u6570<\/p>\n<p id=\"%EF%BC%885%EF%BC%89%E5%88%86%E7%BB%84%E6%9F%A5%E8%AF%A2%EF%BC%88GROUP%20BY%EF%BC%89-toc\" style=\"margin-left:120px\">&#xff08;5&#xff09;\u5206\u7ec4\u67e5\u8be2&#xff08;GROUP BY&#xff09;<\/p>\n<p id=\"%EF%BC%886%EF%BC%89%E5%88%86%E9%A1%B5%E6%9F%A5%E8%AF%A2-toc\" style=\"margin-left:120px\">&#xff08;6&#xff09;\u5206\u9875\u67e5\u8be2<\/p>\n<p id=\"%E4%B8%89%E3%80%81SQL%20%E8%BF%9B%E9%98%B6%EF%BC%9A%E5%A4%9A%E8%A1%A8%E6%93%8D%E4%BD%9C%E4%B8%8E%E9%AB%98%E7%BA%A7%E8%AF%AD%E6%B3%95-toc\" style=\"margin-left:40px\">\u4e09\u3001SQL \u8fdb\u9636&#xff1a;\u591a\u8868\u64cd\u4f5c\u4e0e\u9ad8\u7ea7\u8bed\u6cd5<\/p>\n<p id=\"1.%20%E5%A4%9A%E8%A1%A8%E8%BF%9E%E6%8E%A5%EF%BC%88JOIN%EF%BC%89-toc\" style=\"margin-left:80px\">1. \u591a\u8868\u8fde\u63a5&#xff08;JOIN&#xff09;<\/p>\n<p id=\"%E6%A0%B8%E5%BF%83%E8%BF%9E%E6%8E%A5%E7%B1%BB%E5%9E%8B%EF%BC%9A-toc\" style=\"margin-left:120px\">\u6838\u5fc3\u8fde\u63a5\u7c7b\u578b&#xff1a;<\/p>\n<p id=\"2.%20%E5%AD%90%E6%9F%A5%E8%AF%A2-toc\" style=\"margin-left:80px\">2. \u5b50\u67e5\u8be2<\/p>\n<p id=\"3.%20%E5%B8%B8%E7%94%A8%E9%AB%98%E7%BA%A7%E8%AF%AD%E6%B3%95-toc\" style=\"margin-left:80px\">3. \u5e38\u7528\u9ad8\u7ea7\u8bed\u6cd5<\/p>\n<p id=\"%EF%BC%881%EF%BC%89CASE%20WHEN%EF%BC%9A%E6%9D%A1%E4%BB%B6%E5%88%86%E6%94%AF-toc\" style=\"margin-left:120px\">&#xff08;1&#xff09;CASE WHEN&#xff1a;\u6761\u4ef6\u5206\u652f<\/p>\n<p id=\"%EF%BC%882%EF%BC%89%E4%BA%8B%E5%8A%A1%EF%BC%88TRANSACTION%EF%BC%89-toc\" style=\"margin-left:120px\">&#xff08;2&#xff09;\u4e8b\u52a1&#xff08;TRANSACTION&#xff09;<\/p>\n<p id=\"%EF%BC%883%EF%BC%89%E7%B4%A2%E5%BC%95%EF%BC%88INDEX%EF%BC%89-toc\" style=\"margin-left:120px\">&#xff08;3&#xff09;\u7d22\u5f15&#xff08;INDEX&#xff09;<\/p>\n<p id=\"%E5%9B%9B%E3%80%81SQL%20%E4%BC%98%E5%8C%96%EF%BC%88%E8%BF%9B%E9%98%B6%E5%BF%85%E5%A4%87%EF%BC%89-toc\" style=\"margin-left:40px\">\u56db\u3001SQL \u4f18\u5316&#xff08;\u8fdb\u9636\u5fc5\u5907&#xff09;<\/p>\n<p id=\"%E4%BA%94%E3%80%81%E5%AE%9E%E6%88%98%E7%BB%83%E4%B9%A0-toc\" style=\"margin-left:40px\">\u4e94\u3001\u5b9e\u6218\u7ec3\u4e60<\/p>\n<p id=\"%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:80px\">\u603b\u7ed3<\/p>\n<hr id=\"hr-toc\" \/>\n<p>SQL\u8bed\u53e5\u662f\u64cd\u4f5c\u6570\u636e\u5e93\u7684\u6838\u5fc3&#xff0c;\u65e0\u8bba\u662fMysql\u3001PostgreSQL\u3001SQL Server\u3001Oracle\u90fd\u9700\u8981\u901a\u8fc7SQL\u8bed\u53e5\u8fdb\u884c\u64cd\u4f5c\u3002\u56e0\u6b64&#xff0c;\u53ea\u8981\u638c\u63e1\u4e86SQL\u8bed\u53e5&#xff0c;\u4eca\u540e\u4e0d\u8bba\u9047\u5230\u4ec0\u4e48\u7c7b\u578b\u7684\u5173\u7cfb\u578b\u6570\u636e\u5e93\u90fd\u80fd\u5229\u7528SQL\u8bed\u53e5\u8fdb\u884c\u589e\u5220\u6539\u67e5\u3002<\/p>\n<h4 id=\"1.%20%E4%BB%80%E4%B9%88%E6%98%AF%20SQL\">1. \u4ec0\u4e48\u662f SQL<\/h4>\n<p>\u5728\u5b66\u4e60SQL\u8bed\u53e5\u4e4b\u524d&#xff0c;\u6211\u4eec\u5148\u6765\u4e86\u89e3\u4e00\u4e0b\u4ec0\u4e48\u662fSQL\u8bed\u53e5\u3002<\/p>\n<p>SQL&#xff08;Structured Query Language&#xff09;\u662f\u7ed3\u6784\u5316\u67e5\u8be2\u8bed\u8a00&#xff0c;\u7528\u4e8e\u7ba1\u7406\u548c\u64cd\u4f5c\u5173\u7cfb\u578b\u6570\u636e\u5e93&#xff08;\u5982 MySQL\u3001PostgreSQL\u3001SQL Server\u3001Oracle&#xff09;&#xff0c;\u6838\u5fc3\u80fd\u529b\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>\u6570\u636e\u67e5\u8be2&#xff08;\u6700\u5e38\u7528&#xff09;<\/li>\n<li>\u6570\u636e\u65b0\u589e \/ \u4fee\u6539 \/ \u5220\u9664<\/li>\n<li>\u6570\u636e\u5e93 \/ \u8868\u7ed3\u6784\u7ba1\u7406<\/li>\n<li>\u6743\u9650\u63a7\u5236\u7b49<\/li>\n<\/ul>\n<p>\u7b80\u5355\u6765\u8bf4&#xff1a;SQL\u662f\u4e00\u79cd\u7528\u4e8e\u64cd\u4f5c\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7684\u8bed\u8a00\u3002\u5982\u540cjava\u548cC&#043;&#043;\u7f16\u5199\u7a0b\u5e8f\u4e00\u6837&#xff0c;SQL\u4e0d\u540c\u7684\u70b9\u5728\u4e8e\u64cd\u4f5c\u6570\u636e\u5e93\u3002\u5982\u679c\u8bfb\u8005\u6709\u9ad8\u7ea7\u7f16\u7a0b\u8bed\u8a00\u7684\u57fa\u7840\u7684\u8bdd&#xff0c;\u5bf9\u4e8eSQL\u8bed\u53e5\u7684\u5b66\u4e60\u4f1a\u66f4\u52a0\u5f97\u5fc3\u5e94\u624b\u3002<\/p>\n<h4 id=\"2.%20%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87%EF%BC%88%E6%96%B0%E6%89%8B%E6%8E%A8%E8%8D%90%EF%BC%89\">2. \u73af\u5883\u51c6\u5907&#xff08;\u65b0\u624b\u63a8\u8350&#xff09;<\/h4>\n<ul>\n<li>\u672c\u5730&#xff1a;\u5b89\u88c5 MySQL &#043; Navicat\/DBeaver&#xff08;\u53ef\u89c6\u5316\u5de5\u5177&#xff09;<\/li>\n<li>\u5728\u7ebf&#xff1a;\u4f7f\u7528 SQL Fiddle\u3001DB Fiddle \u7b49\u5728\u7ebf\u6570\u636e\u5e93\u5e73\u53f0&#xff0c;\u65e0\u9700\u5b89\u88c5\u5373\u53ef\u7ec3\u4e60<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u4e00\u4e9b\u5e38\u89c1\u7684SQL\u8bed\u53e5&#xff0c;\u80fd\u591f\u5e2e\u52a9\u4f60\u4ece0\u52301\u638c\u63e1SQL\u8bed\u53e5\u3002&#xff08;SQL\u8bed\u53e5\u4e0d\u533a\u5206\u5927\u5c0f\u5199&#xff0c;\u5373\u5bf9\u5927\u5c0f\u5199\u4e0d\u654f\u611f&#xff0c;\u56e0\u6b64\u4ee5\u4e0b\u5927\u5199\u5b57\u6bcd\u5747\u53ef\u4ee5\u6539\u4e3a\u5c0f\u5199&#xff09;<\/p>\n<h3 id=\"%E4%BA%8C%E3%80%81SQL%20%E5%85%A5%E9%97%A8%EF%BC%9A%E6%A0%B8%E5%BF%83%E8%AF%AD%E6%B3%95%EF%BC%88CRUD%EF%BC%89\">\u4e8c\u3001SQL \u5165\u95e8&#xff1a;\u6838\u5fc3\u8bed\u6cd5&#xff08;CRUD&#xff09;<\/h3>\n<h4 id=\"1.%20%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%8E%E8%A1%A8%E6%93%8D%E4%BD%9C%EF%BC%88DDL%EF%BC%89\">1. \u6570\u636e\u5e93\u4e0e\u8868\u64cd\u4f5c&#xff08;DDL&#xff09;<\/h4>\n<p>\u5148\u638c\u63e1\u5982\u4f55\u521b\u5efa \/ \u67e5\u770b \/ \u5220\u9664\u6570\u636e\u5e93\u548c\u8868&#xff0c;\u8fd9\u662f\u64cd\u4f5c\u6570\u636e\u7684\u57fa\u7840\u3002<\/p>\n<p>&#8212; 1. \u6570\u636e\u5e93\u64cd\u4f5c<br \/>\nCREATE DATABASE IF NOT EXISTS test_db; &#8212; \u521b\u5efa\u6570\u636e\u5e93&#xff08;\u907f\u514d\u91cd\u590d&#xff09;<br \/>\nUSE test_db; &#8212; \u5207\u6362\u5230\u76ee\u6807\u6570\u636e\u5e93<br \/>\nDROP DATABASE IF EXISTS test_db; &#8212; \u5220\u9664\u6570\u636e\u5e93<\/p>\n<p>&#8212; 2. \u8868\u64cd\u4f5c&#xff08;\u4ee5\u5b66\u751f\u8868\u4e3a\u4f8b&#xff09;<br \/>\nCREATE TABLE IF NOT EXISTS student (<br \/>\n    id INT PRIMARY KEY AUTO_INCREMENT, &#8212; \u4e3b\u952e&#043;\u81ea\u589e<br \/>\n    name VARCHAR(50) NOT NULL, &#8212; \u59d3\u540d&#xff08;\u975e\u7a7a&#xff09;<br \/>\n    age INT, &#8212; \u5e74\u9f84<br \/>\n    gender VARCHAR(10), &#8212; \u6027\u522b<br \/>\n    score DECIMAL(5,2), &#8212; \u5206\u6570&#xff08;5\u4f4d\u6570\u5b57&#xff0c;2\u4f4d\u5c0f\u6570&#xff09;<br \/>\n    create_time DATETIME DEFAULT CURRENT_TIMESTAMP &#8212; \u521b\u5efa\u65f6\u95f4&#xff08;\u9ed8\u8ba4\u5f53\u524d\u65f6\u95f4&#xff09;<br \/>\n);<\/p>\n<p>&#8212; \u67e5\u770b\u8868\u7ed3\u6784<br \/>\nDESC student;<\/p>\n<p>&#8212; \u4fee\u6539\u8868&#xff08;\u6dfb\u52a0\u5b57\u6bb5&#xff09;<br \/>\nALTER TABLE student ADD COLUMN class VARCHAR(20);<\/p>\n<p>&#8212; \u5220\u9664\u8868<br \/>\nDROP TABLE IF EXISTS student;<\/p>\n<h4 id=\"2.%20%E6%95%B0%E6%8D%AE%E6%93%8D%E4%BD%9C%EF%BC%88DML%EF%BC%89%EF%BC%9A%E5%A2%9E%E5%88%A0%E6%94%B9\">2. \u6570\u636e\u64cd\u4f5c&#xff08;DML&#xff09;&#xff1a;\u589e\u5220\u6539<\/h4>\n<p>&#8212; 1. \u65b0\u589e\u6570\u636e&#xff08;INSERT&#xff09;<br \/>\n&#8212; \u65b9\u5f0f1&#xff1a;\u6307\u5b9a\u5b57\u6bb5<br \/>\nINSERT INTO student (name, age, gender, score, class)<br \/>\nVALUES (&#039;\u5f20\u4e09&#039;, 18, &#039;\u7537&#039;, 90.5, &#039;\u9ad8\u4e00(1)\u73ed&#039;);<\/p>\n<p>&#8212; \u65b9\u5f0f2&#xff1a;\u6279\u91cf\u65b0\u589e<br \/>\nINSERT INTO student (name, age, gender, score, class)<br \/>\nVALUES<br \/>\n(&#039;\u674e\u56db&#039;, 17, &#039;\u5973&#039;, 88.0, &#039;\u9ad8\u4e00(1)\u73ed&#039;),<br \/>\n(&#039;\u738b\u4e94&#039;, 18, &#039;\u7537&#039;, 95.5, &#039;\u9ad8\u4e00(2)\u73ed&#039;);<\/p>\n<p>&#8212; 2. \u4fee\u6539\u6570\u636e&#xff08;UPDATE&#xff09;&#xff1a;\u5fc5\u987b\u52a0WHERE&#xff0c;\u5426\u5219\u4fee\u6539\u5168\u8868&#xff01;<br \/>\nUPDATE student<br \/>\nSET score &#061; 92.0, class &#061; &#039;\u9ad8\u4e00(1)\u73ed&#039;<br \/>\nWHERE id &#061; 2;<\/p>\n<p>&#8212; 3. \u5220\u9664\u6570\u636e&#xff08;DELETE&#xff09;&#xff1a;\u5fc5\u987b\u52a0WHERE&#xff0c;\u5426\u5219\u5220\u9664\u5168\u8868&#xff01;<br \/>\nDELETE FROM student WHERE id &#061; 3;<\/p>\n<p>&#8212; \u6e05\u7a7a\u8868&#xff08;\u81ea\u589e\u4e3b\u952e\u91cd\u7f6e&#xff09;<br \/>\nTRUNCATE TABLE student;<\/p>\n<h4 id=\"3.%20%E6%95%B0%E6%8D%AE%E6%9F%A5%E8%AF%A2%EF%BC%88DQL%EF%BC%89%EF%BC%9A%E6%9C%80%E6%A0%B8%E5%BF%83%E7%9A%84%20SELECT\">3. \u6570\u636e\u67e5\u8be2&#xff08;DQL&#xff09;&#xff1a;\u6700\u6838\u5fc3\u7684 SELECT<\/h4>\n<p>\u67e5\u8be2\u662f SQL \u6700\u5e38\u7528\u7684\u529f\u80fd&#xff0c;\u4ece\u7b80\u5355\u5230\u590d\u6742\u9010\u6b65\u638c\u63e1&#xff1a;<\/p>\n<h5 id=\"%EF%BC%881%EF%BC%89%E5%9F%BA%E7%A1%80%E6%9F%A5%E8%AF%A2\">&#xff08;1&#xff09;\u57fa\u7840\u67e5\u8be2<\/h5>\n<p>&#8212; \u67e5\u8be2\u6240\u6709\u5b57\u6bb5&#xff08;*&#xff09;&#xff1a;\u751f\u4ea7\u73af\u5883\u5c3d\u91cf\u907f\u514d&#xff0c;\u6307\u5b9a\u5b57\u6bb5\u66f4\u9ad8\u6548<br \/>\nSELECT * FROM student;<\/p>\n<p>&#8212; \u67e5\u8be2\u6307\u5b9a\u5b57\u6bb5<br \/>\nSELECT name, age, score FROM student;<\/p>\n<p>&#8212; \u53bb\u91cd\u67e5\u8be2&#xff08;DISTINCT&#xff09;<br \/>\nSELECT DISTINCT class FROM student;<\/p>\n<p>&#8212; \u522b\u540d&#xff08;AS&#xff09;&#xff1a;\u7b80\u5316\u5b57\u6bb5\/\u8868\u540d<br \/>\nSELECT name AS \u59d3\u540d, age AS \u5e74\u9f84, score AS \u5206\u6570 FROM student AS s;<\/p>\n<h5 id=\"%EF%BC%882%EF%BC%89%E6%9D%A1%E4%BB%B6%E6%9F%A5%E8%AF%A2%EF%BC%88WHERE%EF%BC%89\">&#xff08;2&#xff09;\u6761\u4ef6\u67e5\u8be2&#xff08;WHERE&#xff09;<\/h5>\n<p>&#8212; \u57fa\u672c\u6761\u4ef6&#xff1a;&#061;\u3001&gt;\u3001&lt;\u3001&gt;&#061;\u3001&lt;&#061;\u3001!&#061;\/&lt;&gt;<br \/>\nSELECT * FROM student WHERE score &gt;&#061; 90;<\/p>\n<p>&#8212; \u591a\u6761\u4ef6&#xff1a;AND&#xff08;\u4e14&#xff09;\u3001OR&#xff08;\u6216&#xff09;\u3001NOT&#xff08;\u975e&#xff09;<br \/>\nSELECT * FROM student WHERE age &gt; 17 AND gender &#061; &#039;\u5973&#039;;<\/p>\n<p>&#8212; \u8303\u56f4\u67e5\u8be2&#xff1a;BETWEEN&#8230;AND&#8230;<br \/>\nSELECT * FROM student WHERE score BETWEEN 85 AND 95;<\/p>\n<p>&#8212; \u6a21\u7cca\u67e5\u8be2&#xff1a;LIKE&#xff08;%\u4efb\u610f\u5b57\u7b26&#xff0c;_\u5355\u4e2a\u5b57\u7b26&#xff09;<br \/>\nSELECT * FROM student WHERE name LIKE &#039;\u5f20%&#039;; &#8212; \u59d3\u5f20\u7684\u6240\u6709\u540d\u5b57<br \/>\nSELECT * FROM student WHERE name LIKE &#039;\u5f20_&#039;; &#8212; \u59d3\u5f20\u4e14\u540d\u5b572\u4e2a\u5b57<\/p>\n<p>&#8212; \u7a7a\u503c\u5224\u65ad&#xff1a;IS NULL \/ IS NOT NULL<br \/>\nSELECT * FROM student WHERE age IS NOT NULL;<\/p>\n<p>&#8212; \u679a\u4e3e\u67e5\u8be2&#xff1a;IN<br \/>\nSELECT * FROM student WHERE class IN (&#039;\u9ad8\u4e00(1)\u73ed&#039;, &#039;\u9ad8\u4e00(2)\u73ed&#039;);<\/p>\n<h5 id=\"%EF%BC%883%EF%BC%89%E6%8E%92%E5%BA%8F%EF%BC%88ORDER%20BY%EF%BC%89\">&#xff08;3&#xff09;\u6392\u5e8f&#xff08;ORDER BY&#xff09;<\/h5>\n<p>&#8212; \u5347\u5e8f&#xff08;ASC&#xff0c;\u9ed8\u8ba4&#xff09;\u3001\u964d\u5e8f&#xff08;DESC&#xff09;<br \/>\nSELECT * FROM student ORDER BY score DESC, age ASC;<\/p>\n<h5 id=\"%EF%BC%884%EF%BC%89%E8%81%9A%E5%90%88%E5%87%BD%E6%95%B0\">&#xff08;4&#xff09;\u805a\u5408\u51fd\u6570<\/h5>\n<p>\u7528\u4e8e\u7edf\u8ba1\u6570\u636e&#xff0c;\u5e38\u7528&#xff1a;COUNT&#xff08;\u8ba1\u6570&#xff09;\u3001SUM&#xff08;\u6c42\u548c&#xff09;\u3001AVG&#xff08;\u5e73\u5747&#xff09;\u3001MAX&#xff08;\u6700\u5927&#xff09;\u3001MIN&#xff08;\u6700\u5c0f&#xff09;<\/p>\n<p>&#8212; \u7edf\u8ba1\u603b\u4eba\u6570<br \/>\nSELECT COUNT(*) AS \u603b\u4eba\u6570 FROM student;<\/p>\n<p>&#8212; \u7edf\u8ba1\u7537\u751f\u4eba\u6570&#xff08;COUNT\u6307\u5b9a\u5b57\u6bb5\u907f\u514dNULL&#xff09;<br \/>\nSELECT COUNT(id) AS \u7537\u751f\u4eba\u6570 FROM student WHERE gender &#061; &#039;\u7537&#039;;<\/p>\n<p>&#8212; \u5e73\u5747\u5206\u3001\u603b\u5206\u3001\u6700\u9ad8\u5206<br \/>\nSELECT<br \/>\n    AVG(score) AS \u5e73\u5747\u5206,<br \/>\n    SUM(score) AS \u603b\u5206,<br \/>\n    MAX(score) AS \u6700\u9ad8\u5206<br \/>\nFROM student;<\/p>\n<h5 id=\"%EF%BC%885%EF%BC%89%E5%88%86%E7%BB%84%E6%9F%A5%E8%AF%A2%EF%BC%88GROUP%20BY%EF%BC%89\">&#xff08;5&#xff09;\u5206\u7ec4\u67e5\u8be2&#xff08;GROUP BY&#xff09;<\/h5>\n<p>\u7ed3\u5408\u805a\u5408\u51fd\u6570&#xff0c;\u6309\u6307\u5b9a\u5b57\u6bb5\u5206\u7ec4\u7edf\u8ba1&#xff1a;<\/p>\n<p>&#8212; \u6309\u73ed\u7ea7\u5206\u7ec4&#xff0c;\u7edf\u8ba1\u6bcf\u4e2a\u73ed\u7684\u4eba\u6570\u3001\u5e73\u5747\u5206<br \/>\nSELECT<br \/>\n    class AS \u73ed\u7ea7,<br \/>\n    COUNT(*) AS \u4eba\u6570,<br \/>\n    AVG(score) AS \u5e73\u5747\u5206<br \/>\nFROM student<br \/>\nGROUP BY class;<\/p>\n<p>&#8212; \u5206\u7ec4\u540e\u7b5b\u9009&#xff1a;HAVING&#xff08;\u533a\u522b\u4e8eWHERE&#xff1a;WHERE\u7b5b\u9009\u884c&#xff0c;HAVING\u7b5b\u9009\u5206\u7ec4&#xff09;<br \/>\nSELECT<br \/>\n    class AS \u73ed\u7ea7,<br \/>\n    COUNT(*) AS \u4eba\u6570<br \/>\nFROM student<br \/>\nGROUP BY class<br \/>\nHAVING COUNT(*) &gt; 5; &#8212; \u7b5b\u9009\u4eba\u6570\u5927\u4e8e5\u7684\u73ed\u7ea7<\/p>\n<h5 id=\"%EF%BC%886%EF%BC%89%E5%88%86%E9%A1%B5%E6%9F%A5%E8%AF%A2\">&#xff08;6&#xff09;\u5206\u9875\u67e5\u8be2<\/h5>\n<p>\u4e0d\u540c\u6570\u636e\u5e93\u8bed\u6cd5\u7565\u6709\u5dee\u5f02&#xff0c;\u65b0\u624b\u91cd\u70b9\u638c\u63e1 MySQL&#xff1a;<\/p>\n<p>&#8212; MySQL&#xff1a;LIMIT \u8d77\u59cb\u4f4d\u7f6e&#xff08;\u4ece0\u5f00\u59cb&#xff09;, \u6761\u6570<br \/>\nSELECT * FROM student LIMIT 0, 10; &#8212; \u7b2c1\u9875&#xff0c;\u6bcf\u987510\u6761<br \/>\nSELECT * FROM student LIMIT 10, 10; &#8212; \u7b2c2\u9875&#xff0c;\u6bcf\u987510\u6761<\/p>\n<p>&#8212; SQL Server&#xff1a;TOP \/ OFFSET&#8230;FETCH<br \/>\nSELECT TOP 10 * FROM student;<\/p>\n<p>&#8212; Oracle&#xff1a;ROWNUM<br \/>\nSELECT * FROM (SELECT *, ROWNUM rn FROM student) WHERE rn BETWEEN 1 AND 10;<\/p>\n<h3 id=\"%E4%B8%89%E3%80%81SQL%20%E8%BF%9B%E9%98%B6%EF%BC%9A%E5%A4%9A%E8%A1%A8%E6%93%8D%E4%BD%9C%E4%B8%8E%E9%AB%98%E7%BA%A7%E8%AF%AD%E6%B3%95\">\u4e09\u3001SQL \u8fdb\u9636&#xff1a;\u591a\u8868\u64cd\u4f5c\u4e0e\u9ad8\u7ea7\u8bed\u6cd5<\/h3>\n<h4 id=\"1.%20%E5%A4%9A%E8%A1%A8%E8%BF%9E%E6%8E%A5%EF%BC%88JOIN%EF%BC%89\">1. \u591a\u8868\u8fde\u63a5&#xff08;JOIN&#xff09;<\/h4>\n<p>\u5f53\u6570\u636e\u5206\u5e03\u5728\u591a\u5f20\u8868\u65f6&#xff08;\u5982\u5b66\u751f\u8868 &#043; \u6210\u7ee9\u8868 &#043; \u8bfe\u7a0b\u8868&#xff09;&#xff0c;\u9700\u8981\u8fde\u63a5\u67e5\u8be2&#xff1a;<\/p>\n<p>\u5148\u521b\u5efa\u5173\u8054\u8868\u793a\u4f8b&#xff1a;<\/p>\n<p>&#8212; \u8bfe\u7a0b\u8868<br \/>\nCREATE TABLE course (<br \/>\n    cid INT PRIMARY KEY AUTO_INCREMENT,<br \/>\n    cname VARCHAR(50) NOT NULL &#8212; \u8bfe\u7a0b\u540d<br \/>\n);<\/p>\n<p>&#8212; \u6210\u7ee9\u8868&#xff08;\u5173\u8054\u5b66\u751f\u548c\u8bfe\u7a0b&#xff09;<br \/>\nCREATE TABLE score (<br \/>\n    sid INT, &#8212; \u5173\u8054student.id<br \/>\n    cid INT, &#8212; \u5173\u8054course.cid<br \/>\n    score DECIMAL(5,2),<br \/>\n    PRIMARY KEY (sid, cid), &#8212; \u590d\u5408\u4e3b\u952e<br \/>\n    FOREIGN KEY (sid) REFERENCES student(id), &#8212; \u5916\u952e\u7ea6\u675f<br \/>\n    FOREIGN KEY (cid) REFERENCES course(cid)<br \/>\n);<\/p>\n<h5 id=\"%E6%A0%B8%E5%BF%83%E8%BF%9E%E6%8E%A5%E7%B1%BB%E5%9E%8B%EF%BC%9A\">\u6838\u5fc3\u8fde\u63a5\u7c7b\u578b&#xff1a;<\/h5>\n<p>&#8212; \u5185\u8fde\u63a5&#xff08;INNER JOIN&#xff09;&#xff1a;\u53ea\u8fd4\u56de\u4e24\u8868\u5339\u914d\u7684\u6570\u636e<br \/>\nSELECT<br \/>\n    s.name AS \u5b66\u751f\u59d3\u540d,<br \/>\n    c.cname AS \u8bfe\u7a0b\u540d,<br \/>\n    sc.score AS \u5206\u6570<br \/>\nFROM student s<br \/>\nINNER JOIN score sc ON s.id &#061; sc.sid<br \/>\nINNER JOIN course c ON sc.cid &#061; c.cid;<\/p>\n<p>&#8212; \u5de6\u8fde\u63a5&#xff08;LEFT JOIN&#xff09;&#xff1a;\u8fd4\u56de\u5de6\u8868\u6240\u6709\u6570\u636e&#xff0c;\u53f3\u8868\u65e0\u5339\u914d\u5219\u4e3aNULL<br \/>\nSELECT<br \/>\n    s.name AS \u5b66\u751f\u59d3\u540d,<br \/>\n    c.cname AS \u8bfe\u7a0b\u540d,<br \/>\n    sc.score AS \u5206\u6570<br \/>\nFROM student s<br \/>\nLEFT JOIN score sc ON s.id &#061; sc.sid<br \/>\nLEFT JOIN course c ON sc.cid &#061; c.cid;<\/p>\n<p>&#8212; \u53f3\u8fde\u63a5&#xff08;RIGHT JOIN&#xff09;&#xff1a;\u8fd4\u56de\u53f3\u8868\u6240\u6709\u6570\u636e&#xff0c;\u5de6\u8868\u65e0\u5339\u914d\u5219\u4e3aNULL<br \/>\n&#8212; \u5168\u8fde\u63a5&#xff08;FULL JOIN&#xff09;&#xff1a;\u8fd4\u56de\u4e24\u8868\u6240\u6709\u6570\u636e&#xff08;MySQL\u4e0d\u652f\u6301&#xff0c;\u9700\u7528UNION\u6a21\u62df&#xff09;<\/p>\n<h4 id=\"2.%20%E5%AD%90%E6%9F%A5%E8%AF%A2\">2. \u5b50\u67e5\u8be2<\/h4>\n<p>\u5c06\u4e00\u4e2a\u67e5\u8be2\u7ed3\u679c\u4f5c\u4e3a\u53e6\u4e00\u4e2a\u67e5\u8be2\u7684\u6761\u4ef6 \/ \u6570\u636e\u6e90&#xff0c;\u5206\u4e3a&#xff1a;<\/p>\n<ul>\n<li>\u6807\u91cf\u5b50\u67e5\u8be2&#xff08;\u8fd4\u56de\u5355\u4e2a\u503c&#xff09;<\/li>\n<li>\u5217\u5b50\u67e5\u8be2&#xff08;\u8fd4\u56de\u4e00\u5217&#xff09;<\/li>\n<li>\u884c\u5b50\u67e5\u8be2&#xff08;\u8fd4\u56de\u4e00\u884c&#xff09;<\/li>\n<li>\u8868\u5b50\u67e5\u8be2&#xff08;\u8fd4\u56de\u591a\u884c\u591a\u5217&#xff09;<\/li>\n<\/ul>\n<p>&#8212; \u6807\u91cf\u5b50\u67e5\u8be2&#xff1a;\u67e5\u8be2\u5206\u6570\u9ad8\u4e8e\u5e73\u5747\u5206\u7684\u5b66\u751f<br \/>\nSELECT name, score FROM student<br \/>\nWHERE score &gt; (SELECT AVG(score) FROM student);<\/p>\n<p>&#8212; \u5217\u5b50\u67e5\u8be2&#xff1a;\u67e5\u8be2\u9ad8\u4e00(1)\u73ed\u7684\u6240\u6709\u5b66\u751f\u6210\u7ee9<br \/>\nSELECT * FROM score<br \/>\nWHERE sid IN (SELECT id FROM student WHERE class &#061; &#039;\u9ad8\u4e00(1)\u73ed&#039;);<\/p>\n<p>&#8212; \u8868\u5b50\u67e5\u8be2&#xff1a;\u5c06\u5b50\u67e5\u8be2\u7ed3\u679c\u4f5c\u4e3a\u4e34\u65f6\u8868<br \/>\nSELECT t.name, t.\u5e73\u5747\u5206<br \/>\nFROM (<br \/>\n    SELECT class, AVG(score) AS \u5e73\u5747\u5206 FROM student GROUP BY class<br \/>\n) t<br \/>\nWHERE t.\u5e73\u5747\u5206 &gt; 90;<\/p>\n<h4 id=\"3.%20%E5%B8%B8%E7%94%A8%E9%AB%98%E7%BA%A7%E8%AF%AD%E6%B3%95\">3. \u5e38\u7528\u9ad8\u7ea7\u8bed\u6cd5<\/h4>\n<h5 id=\"%EF%BC%881%EF%BC%89CASE%20WHEN%EF%BC%9A%E6%9D%A1%E4%BB%B6%E5%88%86%E6%94%AF\">&#xff08;1&#xff09;CASE WHEN&#xff1a;\u6761\u4ef6\u5206\u652f<\/h5>\n<p>&#8212; \u7ed9\u5206\u6570\u5206\u7ea7<br \/>\nSELECT<br \/>\n    name,<br \/>\n    score,<br \/>\n    CASE<br \/>\n        WHEN score &gt;&#061; 90 THEN &#039;\u4f18\u79c0&#039;<br \/>\n        WHEN score &gt;&#061; 80 THEN &#039;\u826f\u597d&#039;<br \/>\n        WHEN score &gt;&#061; 60 THEN &#039;\u53ca\u683c&#039;<br \/>\n        ELSE &#039;\u4e0d\u53ca\u683c&#039;<br \/>\n    END AS \u7b49\u7ea7<br \/>\nFROM student;<\/p>\n<h5 id=\"%EF%BC%882%EF%BC%89%E4%BA%8B%E5%8A%A1%EF%BC%88TRANSACTION%EF%BC%89\">&#xff08;2&#xff09;\u4e8b\u52a1&#xff08;TRANSACTION&#xff09;<\/h5>\n<p>\u4fdd\u8bc1\u591a\u6b65\u64cd\u4f5c\u8981\u4e48\u5168\u6210\u529f&#xff0c;\u8981\u4e48\u5168\u5931\u8d25&#xff08;\u5982\u8f6c\u8d26&#xff09;&#xff1a;<\/p>\n<p>START TRANSACTION; &#8212; \u5f00\u542f\u4e8b\u52a1<br \/>\nUPDATE account SET balance &#061; balance &#8211; 100 WHERE id &#061; 1;<br \/>\nUPDATE account SET balance &#061; balance &#043; 100 WHERE id &#061; 2;<br \/>\nCOMMIT; &#8212; \u63d0\u4ea4\u4e8b\u52a1&#xff08;\u751f\u6548&#xff09;<br \/>\n&#8212; ROLLBACK; &#8212; \u56de\u6eda&#xff08;\u51fa\u9519\u65f6\u64a4\u9500\u64cd\u4f5c&#xff09;<\/p>\n<h5 id=\"%EF%BC%883%EF%BC%89%E7%B4%A2%E5%BC%95%EF%BC%88INDEX%EF%BC%89\">&#xff08;3&#xff09;\u7d22\u5f15&#xff08;INDEX&#xff09;<\/h5>\n<p>\u63d0\u5347\u67e5\u8be2\u6548\u7387&#xff0c;\u65b0\u624b\u91cd\u70b9\u638c\u63e1\u521b\u5efa\u8bed\u6cd5&#xff1a;<\/p>\n<p>&#8212; \u521b\u5efa\u7d22\u5f15&#xff08;\u9488\u5bf9\u67e5\u8be2\u9891\u7e41\u7684\u5b57\u6bb5&#xff09;<br \/>\nCREATE INDEX idx_student_name ON student(name);<\/p>\n<p>&#8212; \u67e5\u770b\u7d22\u5f15<br \/>\nSHOW INDEX FROM student;<\/p>\n<p>&#8212; \u5220\u9664\u7d22\u5f15<br \/>\nDROP INDEX idx_student_name ON student;<\/p>\n<h3 id=\"%E5%9B%9B%E3%80%81SQL%20%E4%BC%98%E5%8C%96%EF%BC%88%E8%BF%9B%E9%98%B6%E5%BF%85%E5%A4%87%EF%BC%89\">\u56db\u3001SQL \u4f18\u5316&#xff08;\u8fdb\u9636\u5fc5\u5907&#xff09;<\/h3>\n<li>** \u907f\u514d SELECT ***&#xff1a;\u53ea\u67e5\u8be2\u9700\u8981\u7684\u5b57\u6bb5&#xff0c;\u51cf\u5c11 IO \u548c\u5185\u5b58\u6d88\u8017&#xff1b;<\/li>\n<li>\u7d22\u5f15\u4f18\u5316&#xff1a;\n<ul>\n<li>\u4e3b\u952e \/ \u5916\u952e\u81ea\u52a8\u5efa\u7d22\u5f15&#xff0c;\u67e5\u8be2\u9891\u7e41\u7684\u5b57\u6bb5&#xff08;\u5982 WHERE\u3001JOIN\u3001ORDER BY&#xff09;\u5efa\u7d22\u5f15&#xff1b;<\/li>\n<li>\u907f\u514d\u5728\u7d22\u5f15\u5b57\u6bb5\u4e0a\u505a\u51fd\u6570 \/ \u8fd0\u7b97&#xff08;\u5982WHERE YEAR(create_time) &#061; 2024\u4f1a\u5931\u6548\u7d22\u5f15&#xff09;&#xff1b;<\/li>\n<\/ul>\n<\/li>\n<li>\u51cf\u5c11\u5168\u8868\u626b\u63cf&#xff1a;WHERE \u6761\u4ef6\u5c3d\u91cf\u547d\u4e2d\u7d22\u5f15&#xff0c;\u907f\u514dOR\u3001%\u5f00\u5934\u7684LIKE&#xff1b;<\/li>\n<li>\u5206\u9875\u4f18\u5316&#xff1a;\u5927\u6570\u636e\u91cf\u5206\u9875\u7528LIMIT \u504f\u79fb\u91cf, \u6761\u6570\u65f6&#xff0c;\u504f\u79fb\u91cf\u8d8a\u5927\u8d8a\u6162&#xff0c;\u53ef\u6539\u4e3aWHERE id &gt; \u4e0a\u4e00\u9875\u6700\u5927id LIMIT 10&#xff1b;<\/li>\n<li>\u907f\u514d\u5927\u4e8b\u52a1&#xff1a;\u4e8b\u52a1\u8d8a\u957f&#xff0c;\u9501\u5360\u7528\u65f6\u95f4\u8d8a\u4e45&#xff0c;\u5bb9\u6613\u5f15\u53d1\u5e76\u53d1\u95ee\u9898\u3002<\/li>\n<h3 id=\"%E4%BA%94%E3%80%81%E5%AE%9E%E6%88%98%E7%BB%83%E4%B9%A0\">\u4e94\u3001\u5b9e\u6218\u7ec3\u4e60<\/h3>\n<p>SQL\u8bed\u53e5\u7684\u7cbe\u901a\u9700\u8981\u8fdb\u884c\u5927\u91cf\u7684\u7ec3\u4e60&#xff0c;\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5b66\u4e60\u7684\u5efa\u8bae\u548c\u63a8\u8350\u7ec3\u4e60\u7684\u5e73\u53f0\u3002<\/p>\n<p>\u63a8\u8350\u65b0\u624b\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5de9\u56fa&#xff1a;<\/p>\n<li>\u7ec3\u4e60\u7ecf\u5178 SQL \u9898&#xff1a;LeetCode \u6570\u636e\u5e93\u9898\u5e93&#xff08;\u7b80\u5355 \/ \u4e2d\u7b49\u96be\u5ea6&#xff09;\u3001\u725b\u5ba2\u7f51 SQL \u4e13\u9879&#xff1b;<\/li>\n<li>\u6a21\u62df\u4e1a\u52a1\u573a\u666f&#xff1a;\u5982 \u201c\u7edf\u8ba1\u6bcf\u4e2a\u73ed\u7ea7\u7684\u7537\u5973\u6bd4\u4f8b\u201d\u3001\u201c\u67e5\u8be2\u4e0d\u53ca\u683c\u7684\u5b66\u751f\u53ca\u5bf9\u5e94\u8bfe\u7a0b\u201d\u3002<\/li>\n<h4 id=\"%E6%80%BB%E7%BB%93\">\u603b\u7ed3<\/h4>\n<li>\u6838\u5fc3\u57fa\u7840&#xff1a;SQL \u7684\u6838\u5fc3\u662f CRUD&#xff0c;\u5176\u4e2dSELECT\u67e5\u8be2\u662f\u91cd\u70b9&#xff0c;\u5fc5\u987b\u638c\u63e1\u6761\u4ef6\u3001\u6392\u5e8f\u3001\u805a\u5408\u3001\u5206\u7ec4\u3001\u5206\u9875\u7b49\u57fa\u7840\u8bed\u6cd5&#xff1b;<\/li>\n<li>\u8fdb\u9636\u6838\u5fc3&#xff1a;\u591a\u8868\u8fde\u63a5&#xff08;JOIN&#xff09;\u662f\u5904\u7406\u5173\u8054\u6570\u636e\u7684\u5173\u952e&#xff0c;\u5b50\u67e5\u8be2\u548c CASE WHEN \u80fd\u89e3\u51b3\u590d\u6742\u4e1a\u52a1\u903b\u8f91&#xff1b;<\/li>\n<li>\u5b9e\u6218\u5173\u952e&#xff1a;\u5199 SQL \u65f6\u8981\u6ce8\u610f\u6548\u7387&#xff08;\u7d22\u5f15\u3001\u907f\u514d\u5168\u8868\u626b\u63cf&#xff09;&#xff0c;\u751f\u4ea7\u73af\u5883\u4e2dUPDATE\/DELETE\u5fc5\u987b\u52a0 WHERE \u6761\u4ef6&#xff0c;\u907f\u514d\u8bef\u64cd\u4f5c\u3002<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55<br \/>\n1. \u4ec0\u4e48\u662f SQL<br \/>\n2. \u73af\u5883\u51c6\u5907&#xff08;\u65b0\u624b\u63a8\u8350&#xff09;<br \/>\n\u4e8c\u3001SQL \u5165\u95e8&#xff1a;\u6838\u5fc3\u8bed\u6cd5&#xff08;CRUD&#xff09;<br \/>\n1. \u6570\u636e\u5e93\u4e0e\u8868\u64cd\u4f5c&#xff08;DDL&#xff09;<br \/>\n2. \u6570\u636e\u64cd\u4f5c&#xff08;DML&#xff09;&#xff1a;\u589e\u5220\u6539<br \/>\n3. \u6570\u636e\u67e5\u8be2&#xff08;DQL&#xff09;&#xff1a;\u6700\u6838\u5fc3\u7684 SELECT<br \/>\n&#xff08;1&#xff09;\u57fa\u7840\u67e5\u8be2<br \/>\n&#xff08;2&amp;#xf<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[768,100],"topic":[],"class_list":["post-76031","post","type-post","status-publish","format-standard","hentry","category-server","tag-sql","tag-100"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL\u8bed\u53e5\u4ece\u5165\u95e8\u5230\u7cbe\u901a\uff1a\u53ea\u770b\u8fd9\u4e00\u7bc7\u5c31\u591f\u4e86\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/76031.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL\u8bed\u53e5\u4ece\u5165\u95e8\u5230\u7cbe\u901a\uff1a\u53ea\u770b\u8fd9\u4e00\u7bc7\u5c31\u591f\u4e86\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 1. \u4ec0\u4e48\u662f SQL 2. \u73af\u5883\u51c6\u5907&#xff08;\u65b0\u624b\u63a8\u8350&#xff09; \u4e8c\u3001SQL \u5165\u95e8&#xff1a;\u6838\u5fc3\u8bed\u6cd5&#xff08;CRUD&#xff09; 1. \u6570\u636e\u5e93\u4e0e\u8868\u64cd\u4f5c&#xff08;DDL&#xff09; 2. \u6570\u636e\u64cd\u4f5c&#xff08;DML&#xff09;&#xff1a;\u589e\u5220\u6539 3. \u6570\u636e\u67e5\u8be2&#xff08;DQL&#xff09;&#xff1a;\u6700\u6838\u5fc3\u7684 SELECT &#xff08;1&#xff09;\u57fa\u7840\u67e5\u8be2 &#xff08;2&amp;#xf\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/76031.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-13T11:57:26+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/76031.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/76031.html\",\"name\":\"SQL\u8bed\u53e5\u4ece\u5165\u95e8\u5230\u7cbe\u901a\uff1a\u53ea\u770b\u8fd9\u4e00\u7bc7\u5c31\u591f\u4e86\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-13T11:57:26+00:00\",\"dateModified\":\"2026-02-13T11:57:26+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/76031.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/76031.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/76031.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL\u8bed\u53e5\u4ece\u5165\u95e8\u5230\u7cbe\u901a\uff1a\u53ea\u770b\u8fd9\u4e00\u7bc7\u5c31\u591f\u4e86\uff01\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL\u8bed\u53e5\u4ece\u5165\u95e8\u5230\u7cbe\u901a\uff1a\u53ea\u770b\u8fd9\u4e00\u7bc7\u5c31\u591f\u4e86\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/76031.html","og_locale":"zh_CN","og_type":"article","og_title":"SQL\u8bed\u53e5\u4ece\u5165\u95e8\u5230\u7cbe\u901a\uff1a\u53ea\u770b\u8fd9\u4e00\u7bc7\u5c31\u591f\u4e86\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 1. \u4ec0\u4e48\u662f SQL 2. \u73af\u5883\u51c6\u5907&#xff08;\u65b0\u624b\u63a8\u8350&#xff09; \u4e8c\u3001SQL \u5165\u95e8&#xff1a;\u6838\u5fc3\u8bed\u6cd5&#xff08;CRUD&#xff09; 1. \u6570\u636e\u5e93\u4e0e\u8868\u64cd\u4f5c&#xff08;DDL&#xff09; 2. \u6570\u636e\u64cd\u4f5c&#xff08;DML&#xff09;&#xff1a;\u589e\u5220\u6539 3. \u6570\u636e\u67e5\u8be2&#xff08;DQL&#xff09;&#xff1a;\u6700\u6838\u5fc3\u7684 SELECT &#xff08;1&#xff09;\u57fa\u7840\u67e5\u8be2 &#xff08;2&amp;#xf","og_url":"https:\/\/www.wsisp.com\/helps\/76031.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-13T11:57:26+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/76031.html","url":"https:\/\/www.wsisp.com\/helps\/76031.html","name":"SQL\u8bed\u53e5\u4ece\u5165\u95e8\u5230\u7cbe\u901a\uff1a\u53ea\u770b\u8fd9\u4e00\u7bc7\u5c31\u591f\u4e86\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-13T11:57:26+00:00","dateModified":"2026-02-13T11:57:26+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/76031.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/76031.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/76031.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"SQL\u8bed\u53e5\u4ece\u5165\u95e8\u5230\u7cbe\u901a\uff1a\u53ea\u770b\u8fd9\u4e00\u7bc7\u5c31\u591f\u4e86\uff01"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/76031","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=76031"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/76031\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=76031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=76031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=76031"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=76031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}