{"id":113577,"date":"2026-10-06T21:57:08","date_gmt":"2026-10-06T13:57:08","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/113577.html"},"modified":"2026-10-06T21:57:08","modified_gmt":"2026-10-06T13:57:08","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%ef%bc%9a%e5%9f%ba%e6%9c%ac%e6%9f%a5%e8%af%a2","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/113577.html","title":{"rendered":"MySQL\u6570\u636e\u5e93\uff1a\u57fa\u672c\u67e5\u8be2"},"content":{"rendered":"<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>mysql\u57fa\u672c\u67e5\u8be2\u901a\u5173\u624b\u518c&#xff1a;\u4ececrud\u5230\u5206\u7ec4\u7edf\u8ba1&#xff0c;\u65b0\u624b\u907f\u5751\u5168\u653b\u7565<\/li>\n<li>\n<ul>\n<li>\u4e00\u3001\u5148\u641e\u61c2&#xff1a;\u8868\u662f\u4ec0\u4e48&#xff1f;<\/li>\n<li>\u4e8c\u3001create&#xff1a;\u5148\u5efa\u4e00\u5f20\u8868<\/li>\n<li>\n<ul>\n<li>2.1 \u6700\u7b80\u5355\u7684\u5efa\u8868\u4f8b\u5b50<\/li>\n<li>2.2 \u5927\u767d\u8bdd\u89e3\u91ca\u6bcf\u4e2a\u8bcd<\/li>\n<li>2.3 \u65b0\u624b\u5efa\u8868\u907f\u5751<\/li>\n<\/ul>\n<\/li>\n<li>\u4e09\u3001insert&#xff1a;\u5f80\u8868\u91cc\u52a0\u6570\u636e<\/li>\n<li>\n<ul>\n<li>3.1 \u5355\u884c\u5168\u5217\u63d2\u5165<\/li>\n<li>3.2 \u6307\u5b9a\u5217\u63d2\u5165<\/li>\n<li>3.3 \u4e00\u6b21\u63d2\u591a\u884c<\/li>\n<li>3.4 \u63d2\u5165\u907f\u5751<\/li>\n<\/ul>\n<\/li>\n<li>\u56db\u3001select&#xff1a;\u4ece\u8868\u91cc\u67e5\u6570\u636e<\/li>\n<li>\n<ul>\n<li>4.1 \u67e5\u6240\u6709\u5217<\/li>\n<li>4.2 \u53ea\u67e5\u6307\u5b9a\u5217<\/li>\n<li>4.3 \u7ed9\u5217\u8d77\u4e2a\u522b\u540d<\/li>\n<li>4.4 \u6309\u6761\u4ef6\u7b5b\u9009&#xff1a;where<\/li>\n<li>\n<ul>\n<li>\u5e38\u7528\u6bd4\u8f83\u8fd0\u7b97\u7b26<\/li>\n<li>\u903b\u8f91\u8fd0\u7b97\u7b26<\/li>\n<li>\u6a21\u7cca\u67e5\u8be2&#xff1a;like<\/li>\n<li>\u26a0\ufe0f \u8d85\u7ea7\u5927\u5751&#xff1a;null\u4e0d\u80fd\u7528&#061;\u5224\u65ad<\/li>\n<\/ul>\n<\/li>\n<li>4.5 \u65b0\u624b\u9ad8\u9891\u62a5\u9519&#xff1a;where\u91cc\u7528\u522b\u540d<\/li>\n<li>4.6 \u6392\u5e8f&#xff1a;order by<\/li>\n<li>4.7 \u5206\u9875&#xff1a;limit<\/li>\n<\/ul>\n<\/li>\n<li>\u4e94\u3001update&#xff1a;\u4fee\u6539\u8868\u91cc\u7684\u6570\u636e<\/li>\n<li>\n<ul>\n<li>5.1 \u4fee\u6539\u6307\u5b9a\u884c<\/li>\n<li>5.2 \u2757\ufe0f \u81f4\u547d\u63d0\u9192&#xff1a;\u5343\u4e07\u522b\u5fd8\u5199where<\/li>\n<li>5.3 \u66f4\u65b0\u907f\u5751<\/li>\n<\/ul>\n<\/li>\n<li>\u516d\u3001delete&#xff1a;\u5220\u9664\u8868\u91cc\u7684\u6570\u636e<\/li>\n<li>\n<ul>\n<li>6.1 \u5220\u9664\u6307\u5b9a\u884c<\/li>\n<li>6.2 \u2757\ufe0f \u81f4\u547d\u63d0\u9192&#xff1a;\u5343\u4e07\u522b\u5fd8\u5199where<\/li>\n<li>6.3 \u6e05\u7a7a\u5168\u8868\u7684\u53e6\u4e00\u79cd\u65b9\u5f0f&#xff1a;truncate<\/li>\n<li>6.4 delete\u548ctruncate\u7684\u533a\u522b<\/li>\n<\/ul>\n<\/li>\n<li>\u4e03\u3001\u5206\u7ec4\u7edf\u8ba1&#xff1a;\u805a\u5408\u51fd\u6570 &#043; group by<\/li>\n<li>\n<ul>\n<li>7.1 \u4e94\u4e2a\u5e38\u7528\u805a\u5408\u51fd\u6570<\/li>\n<li>7.2 group by\u5230\u5e95\u5728\u5e72\u561b&#xff1f;<\/li>\n<li>7.3 \u57fa\u672c\u7528\u6cd5&#xff1a;\u5206\u7ec4 &#043; \u805a\u5408<\/li>\n<li>\n<ul>\n<li>\u4f8b1&#xff1a;\u7edf\u8ba1\u6bcf\u4e2a\u73ed\u6709\u591a\u5c11\u4eba<\/li>\n<li>\u4f8b2&#xff1a;\u7edf\u8ba1\u6bcf\u4e2a\u73ed\u7684\u6570\u5b66\u6210\u7ee9\u60c5\u51b5<\/li>\n<li>\u4f8b3&#xff1a;\u591a\u5b57\u6bb5\u5206\u7ec4<\/li>\n<\/ul>\n<\/li>\n<li>7.4 \u65b0\u624b\u7075\u9b42\u62f7\u95ee&#xff1a;\u5206\u5b8c\u7ec4&#xff0c;\u539f\u59cb\u884c\u8fd8\u5728\u5417&#xff1f;<\/li>\n<li>7.5 \u60f3\u8981\u660e\u7ec6 &#043; \u5206\u7ec4\u7edf\u8ba1&#xff1f;\u7528\u7a97\u53e3\u51fd\u6570<\/li>\n<li>7.6 having&#xff1a;\u5206\u7ec4\u540e\u7b5b\u9009<\/li>\n<li>7.7 where\u548chaving\u7684\u533a\u522b<\/li>\n<\/ul>\n<\/li>\n<li>\u516b\u3001\u5fc5\u61c2\u5e95\u5c42\u903b\u8f91&#xff1a;sql\u6267\u884c\u987a\u5e8f<\/li>\n<li>\n<ul>\n<li>8.1 \u771f\u5b9e\u6267\u884c\u987a\u5e8f<\/li>\n<li>8.2 \u5927\u767d\u8bdd\u7c7b\u6bd4&#xff1a;\u505a\u83dc\u7684\u987a\u5e8f<\/li>\n<li>8.3 \u61c2\u4e86\u6267\u884c\u987a\u5e8f\u6709\u5565\u7528&#xff1f;<\/li>\n<\/ul>\n<\/li>\n<li>\u4e5d\u3001\u65b0\u624b\u907f\u5751\u7ec8\u6781\u6e05\u5355<\/li>\n<li>\u5341\u3001\u6700\u540e&#xff1a;ai\u65f6\u4ee3\u600e\u4e48\u5b66<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>mysql\u57fa\u672c\u67e5\u8be2\u901a\u5173\u624b\u518c&#xff1a;\u4ececrud\u5230\u5206\u7ec4\u7edf\u8ba1&#xff0c;\u65b0\u624b\u907f\u5751\u5168\u653b\u7565<\/h2>\n<p>\u5f88\u591a\u521a\u63a5\u89e6mysql\u7684\u540c\u5b66&#xff0c;\u4e00\u542c\u5230\u201c\u6570\u636e\u5e93\u201d\u201csql\u201d\u5c31\u89c9\u5f97\u5f88\u9ad8\u6df1\u3002\u5176\u5b9e\u5b8c\u5168\u4e0d\u7528\u6015&#xff0c;\u4f60\u5c31\u628a\u6570\u636e\u5e93\u8868\u5f53\u6210\u4e00\u5f20\u73ed\u7ea7\u82b1\u540d\u518c&#xff0c;\u6240\u6709\u64cd\u4f5c\u5168\u662f\u65e5\u5e38\u903b\u8f91&#xff1a;<\/p>\n<ul>\n<li>\u753b\u4e00\u5f20\u65b0\u7684\u7a7a\u767d\u8868\u683c &#061; \u5efa\u8868&#xff08;create&#xff09;<\/li>\n<li>\u5f80\u8868\u683c\u91cc\u586b\u65b0\u540c\u5b66\u4fe1\u606f &#061; \u63d2\u5165\u6570\u636e&#xff08;insert&#xff09;<\/li>\n<li>\u4ece\u8868\u683c\u91cc\u627e\u4eba\u3001\u627e\u6210\u7ee9 &#061; \u67e5\u8be2\u6570\u636e&#xff08;select&#xff09;<\/li>\n<li>\u4fee\u6539\u8868\u683c\u91cc\u5199\u9519\u7684\u4fe1\u606f &#061; \u66f4\u65b0\u6570\u636e&#xff08;update&#xff09;<\/li>\n<li>\u628a\u540c\u5b66\u4ece\u8868\u683c\u91cc\u5212\u6389 &#061; \u5220\u9664\u6570\u636e&#xff08;delete&#xff09;<\/li>\n<\/ul>\n<p>\u8fd9\u56db\u4e2a\u64cd\u4f5c\u5408\u8d77\u6765\u5c31\u662f\u6570\u636e\u5e93\u91cc\u6700\u57fa\u7840\u7684crud\u3002\u4eca\u5929\u54b1\u4eec\u5b8c\u5168\u4ece\u96f6\u8d77\u6b65&#xff0c;\u7528\u5927\u767d\u8bdd&#043;\u53ef\u76f4\u63a5\u8fd0\u884c\u7684\u4f8b\u5b50&#xff0c;\u628amysql\u57fa\u672c\u8bed\u6cd5\u8bb2\u660e\u767d&#xff0c;\u65b0\u624b\u4e5f\u80fd\u770b\u5b8c\u5c31\u4e0a\u624b\u6572\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u5148\u641e\u61c2&#xff1a;\u8868\u662f\u4ec0\u4e48&#xff1f;<\/h3>\n<p>\u8868&#xff0c;\u5c31\u662f\u4e00\u5f20\u6709\u884c\u6709\u5217\u7684\u8868\u683c&#xff0c;\u548cexcel\u91cc\u7684\u8868\u4e00\u6a21\u4e00\u6837&#xff1a;<\/p>\n<ul>\n<li>\u5217&#xff08;\u5b57\u6bb5&#xff09;&#xff1a;\u8868\u683c\u7684\u8868\u5934&#xff0c;\u6bd4\u5982\u59d3\u540d\u3001\u5b66\u53f7\u3001\u8bed\u6587\u6210\u7ee9&#xff0c;\u89c4\u5b9a\u4e86\u8fd9\u4e00\u5217\u80fd\u586b\u4ec0\u4e48\u7c7b\u578b\u7684\u6570\u636e<\/li>\n<li>\u884c&#xff08;\u8bb0\u5f55&#xff09;&#xff1a;\u8868\u683c\u91cc\u7684\u6bcf\u4e00\u884c\u6570\u636e&#xff0c;\u6bd4\u5982\u4e00\u4e2a\u540c\u5b66\u7684\u6240\u6709\u4fe1\u606f\u5c31\u662f\u4e00\u884c\u8bb0\u5f55<\/li>\n<\/ul>\n<p>\u540e\u9762\u6240\u6709\u64cd\u4f5c&#xff0c;\u6211\u4eec\u90fd\u7528\u300c\u5b66\u751f\u6210\u7ee9\u8868\u300d\u5f53\u4f8b\u5b50&#xff0c;\u8ddf\u7740\u6572\u4e00\u904d\u5c31\u80fd\u5b66\u4f1a\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001create&#xff1a;\u5148\u5efa\u4e00\u5f20\u8868<\/h3>\n<p>\u8bf4\u767d\u4e86\u5c31\u662f\u753b\u4e00\u5f20\u7a7a\u767d\u8868\u683c&#xff0c;\u5148\u5b9a\u597d\u6709\u51e0\u5217\u3001\u6bcf\u5217\u53eb\u4ec0\u4e48\u3001\u80fd\u586b\u5565\u3002<\/p>\n<h4>2.1 \u6700\u7b80\u5355\u7684\u5efa\u8868\u4f8b\u5b50<\/h4>\n<p>\u6211\u4eec\u5148\u5efa\u4e00\u5f20\u5b66\u751f\u8868&#xff1a;<\/p>\n<p><span class=\"token keyword\">create<\/span> <span class=\"token keyword\">table<\/span> students <span class=\"token punctuation\">(<\/span><br \/>\n  id <span class=\"token keyword\">int<\/span> <span class=\"token keyword\">unsigned<\/span> <span class=\"token keyword\">primary<\/span> <span class=\"token keyword\">key<\/span> <span class=\"token keyword\">auto_increment<\/span> <span class=\"token keyword\">comment<\/span> <span class=\"token string\">&#039;\u7f16\u53f7&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  sn <span class=\"token keyword\">int<\/span> <span class=\"token operator\">not<\/span> <span class=\"token boolean\">null<\/span> <span class=\"token keyword\">unique<\/span> <span class=\"token keyword\">comment<\/span> <span class=\"token string\">&#039;\u5b66\u53f7&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  name <span class=\"token keyword\">varchar<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">20<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">not<\/span> <span class=\"token boolean\">null<\/span> <span class=\"token keyword\">comment<\/span> <span class=\"token string\">&#039;\u59d3\u540d&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  qq <span class=\"token keyword\">varchar<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">20<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">comment<\/span> <span class=\"token string\">&#039;qq\u53f7&#039;<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>2.2 \u5927\u767d\u8bdd\u89e3\u91ca\u6bcf\u4e2a\u8bcd<\/h4>\n<p>\u4e0d\u7528\u6b7b\u8bb0&#xff0c;\u77e5\u9053\u5927\u6982\u610f\u601d\u5c31\u884c&#xff1a;<\/p>\n<table>\n<tr>\u5173\u952e\u5b57\u5927\u767d\u8bdd\u89e3\u91ca<\/tr>\n<tbody>\n<tr>\n<td>int<\/td>\n<td>\u6574\u6570\u7c7b\u578b&#xff0c;\u8fd9\u4e00\u5217\u53ea\u80fd\u586b\u6574\u6570&#xff0c;\u6bd4\u5982\u5b66\u53f7\u3001\u7f16\u53f7<\/td>\n<\/tr>\n<tr>\n<td>varchar(20)<\/td>\n<td>\u5b57\u7b26\u4e32\u7c7b\u578b&#xff0c;\u80fd\u586b\u6587\u5b57&#xff0c;\u62ec\u53f7\u91cc\u662f\u6700\u5927\u957f\u5ea6&#xff0c;\u6bd4\u5982\u59d3\u540d\u6700\u591a20\u4e2a\u5b57<\/td>\n<\/tr>\n<tr>\n<td>not null<\/td>\n<td>\u8fd9\u4e00\u5217\u4e0d\u80fd\u4e3a\u7a7a&#xff0c;\u5fc5\u987b\u586b\u503c&#xff0c;\u6bd4\u5982\u59d3\u540d\u80af\u5b9a\u4e0d\u80fd\u7a7a\u7740<\/td>\n<\/tr>\n<tr>\n<td>primary key<\/td>\n<td>\u4e3b\u952e&#xff0c;\u76f8\u5f53\u4e8e\u8fd9\u4e00\u884c\u7684\u8eab\u4efd\u8bc1\u53f7&#xff0c;\u552f\u4e00\u4e0d\u91cd\u590d&#xff0c;\u4e00\u822c\u90fd\u7528id\u5f53\u4e3b\u952e<\/td>\n<\/tr>\n<tr>\n<td>auto_increment<\/td>\n<td>\u81ea\u52a8\u9012\u589e&#xff0c;id\u4e0d\u7528\u81ea\u5df1\u586b&#xff0c;\u6570\u636e\u5e93\u4f1a\u81ea\u52a8\u63091\u30012\u30013\u2026\u5e2e\u4f60\u6392\u53f7<\/td>\n<\/tr>\n<tr>\n<td>unique<\/td>\n<td>\u552f\u4e00\u7ea6\u675f&#xff0c;\u8fd9\u4e00\u5217\u7684\u503c\u4e0d\u80fd\u91cd\u590d&#xff0c;\u6bd4\u5982\u5b66\u53f7\u80af\u5b9a\u4e0d\u80fd\u4e24\u4e2a\u4eba\u4e00\u6837<\/td>\n<\/tr>\n<tr>\n<td>comment &#039;xxx&#039;<\/td>\n<td>\u5907\u6ce8&#xff0c;\u76f8\u5f53\u4e8e\u7ed9\u5217\u5199\u6ce8\u91ca&#xff0c;\u65b9\u4fbf\u4ee5\u540e\u770b\u61c2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2.3 \u65b0\u624b\u5efa\u8868\u907f\u5751<\/h4>\n<li>\u8868\u540d\u3001\u5217\u540d\u5168\u90e8\u7528\u82f1\u6587\u5c0f\u5199&#xff0c;\u7528\u4e0b\u5212\u7ebf\u5206\u9694&#xff0c;\u522b\u7528\u4e2d\u6587<\/li>\n<li>\u522b\u7528order\u3001group\u3001name\u8fd9\u79cdmysql\u5173\u952e\u5b57\u5f53\u5217\u540d&#xff0c;\u4f1a\u62a5\u9519<\/li>\n<li>\u5c3d\u91cf\u7ed9\u6bcf\u5217\u8bbe\u7f6e\u9ed8\u8ba4\u503c&#xff0c;\u5c11\u7528null&#xff0c;\u540e\u9762\u4f1a\u8bb2null\u6709\u591a\u5751<\/li>\n<hr \/>\n<h3>\u4e09\u3001insert&#xff1a;\u5f80\u8868\u91cc\u52a0\u6570\u636e<\/h3>\n<p>\u5efa\u5b8c\u7a7a\u8868&#xff0c;\u5c31\u8be5\u5f80\u91cc\u9762\u586b\u6570\u636e\u4e86&#xff0c;\u5c31\u50cf\u5f80\u82b1\u540d\u518c\u91cc\u767b\u65b0\u540c\u5b66\u4fe1\u606f\u3002<\/p>\n<h4>3.1 \u5355\u884c\u5168\u5217\u63d2\u5165<\/h4>\n<p>\u7ed9\u6bcf\u4e00\u5217\u90fd\u6309\u987a\u5e8f\u586b\u503c&#xff0c;\u503c\u7684\u6570\u91cf\u548c\u987a\u5e8f\u5fc5\u987b\u548c\u5efa\u8868\u65f6\u5b8c\u5168\u5bf9\u5e94&#xff1a;<\/p>\n<p><span class=\"token keyword\">insert<\/span> <span class=\"token keyword\">into<\/span> students <span class=\"token keyword\">values<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">100<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">10000<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\u5510\u4e09\u85cf&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token boolean\">null<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5c0f\u63d0\u793a&#xff1a;id\u8bbe\u7f6e\u4e86\u81ea\u52a8\u9012\u589e&#xff0c;\u5176\u5b9e\u53ef\u4ee5\u4e0d\u7528\u5199\u3002\u5982\u679c\u4e0d\u6307\u5b9aid&#xff0c;mysql\u4f1a\u81ea\u52a8\u5e2e\u4f60\u751f\u6210\u9012\u589e\u7684\u7f16\u53f7\u3002<\/p>\n<h4>3.2 \u6307\u5b9a\u5217\u63d2\u5165<\/h4>\n<p>\u53ea\u60f3\u586b\u67d0\u51e0\u5217&#xff0c;\u5176\u4ed6\u5217\u7559\u7a7a\u6216\u8005\u7528\u9ed8\u8ba4\u503c&#xff0c;\u5c31\u6307\u5b9a\u5217\u540d\u518d\u63d2&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u53ea\u586bid\u3001\u5b66\u53f7\u3001\u59d3\u540d&#xff0c;qq\u53f7\u4e0d\u586b<\/span><br \/>\n<span class=\"token keyword\">insert<\/span> <span class=\"token keyword\">into<\/span> students <span class=\"token punctuation\">(<\/span>id<span class=\"token punctuation\">,<\/span> sn<span class=\"token punctuation\">,<\/span> name<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">values<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">101<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">10001<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\u5b59\u609f\u7a7a&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd9\u662f\u5f00\u53d1\u91cc\u6700\u5e38\u7528\u7684\u5199\u6cd5&#xff0c;\u7075\u6d3b\u4e0d\u5bb9\u6613\u9519\u3002<\/p>\n<h4>3.3 \u4e00\u6b21\u63d2\u591a\u884c<\/h4>\n<p>\u4e00\u6761\u4e00\u6761\u63d2\u592a\u6162&#xff0c;\u4e00\u6761\u8bed\u53e5\u53ef\u4ee5\u63d2\u591a\u6761\u6570\u636e&#xff0c;\u4e2d\u95f4\u7528\u9017\u53f7\u9694\u5f00&#xff1a;<\/p>\n<p><span class=\"token keyword\">insert<\/span> <span class=\"token keyword\">into<\/span> students <span class=\"token punctuation\">(<\/span>id<span class=\"token punctuation\">,<\/span> sn<span class=\"token punctuation\">,<\/span> name<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">values<\/span><br \/>\n<span class=\"token punctuation\">(<\/span><span class=\"token number\">102<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">20001<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\u66f9\u5b5f\u5fb7&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">(<\/span><span class=\"token number\">103<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">20002<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\u5b59\u4ef2\u8c0b&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>3.4 \u63d2\u5165\u907f\u5751<\/h4>\n<li>\u5b57\u7b26\u4e32\u3001\u65e5\u671f\u5fc5\u987b\u52a0\u82f1\u6587\u5355\u5f15\u53f7&#xff0c;\u6bd4\u5982&#039;\u5b59\u609f\u7a7a&#039;&#xff0c;\u6570\u5b57\u4e0d\u7528<\/li>\n<li>\u503c\u7684\u6570\u91cf\u3001\u987a\u5e8f\u5fc5\u987b\u548c\u4f60\u6307\u5b9a\u7684\u5217\u4e25\u683c\u5bf9\u5e94<\/li>\n<li>\u6240\u6709\u6807\u70b9\u7b26\u53f7\u90fd\u662f\u82f1\u6587\u534a\u89d2&#xff0c;\u4e2d\u6587\u6807\u70b9\u76f4\u63a5\u62a5\u9519<\/li>\n<hr \/>\n<h3>\u56db\u3001select&#xff1a;\u4ece\u8868\u91cc\u67e5\u6570\u636e<\/h3>\n<p>\u67e5\u8be2\u662f\u65e5\u5e38\u7528\u5f97\u6700\u591a\u7684\u64cd\u4f5c&#xff0c;\u6ca1\u6709\u4e4b\u4e00\u3002\u8bf4\u767d\u4e86\u5c31\u662f\u4ece\u8868\u683c\u91cc\u627e\u51fa\u4f60\u60f3\u8981\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u4e3a\u4e86\u65b9\u4fbf\u6f14\u793a\u67e5\u8be2&#xff0c;\u6211\u4eec\u518d\u5efa\u4e00\u5f20\u6210\u7ee9\u8868\u5e76\u63d2\u5165\u6d4b\u8bd5\u6570\u636e&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u5efa\u6210\u7ee9\u8868<\/span><br \/>\n<span class=\"token keyword\">create<\/span> <span class=\"token keyword\">table<\/span> exam_result <span class=\"token punctuation\">(<\/span><br \/>\n  id <span class=\"token keyword\">int<\/span> <span class=\"token keyword\">unsigned<\/span> <span class=\"token keyword\">primary<\/span> <span class=\"token keyword\">key<\/span> <span class=\"token keyword\">auto_increment<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  name <span class=\"token keyword\">varchar<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">20<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">not<\/span> <span class=\"token boolean\">null<\/span> <span class=\"token keyword\">comment<\/span> <span class=\"token string\">&#039;\u540c\u5b66\u59d3\u540d&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  class <span class=\"token keyword\">varchar<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">comment<\/span> <span class=\"token string\">&#039;\u73ed\u7ea7&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  chinese <span class=\"token keyword\">float<\/span> <span class=\"token keyword\">default<\/span> <span class=\"token number\">0.0<\/span> <span class=\"token keyword\">comment<\/span> <span class=\"token string\">&#039;\u8bed\u6587\u6210\u7ee9&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  math <span class=\"token keyword\">float<\/span> <span class=\"token keyword\">default<\/span> <span class=\"token number\">0.0<\/span> <span class=\"token keyword\">comment<\/span> <span class=\"token string\">&#039;\u6570\u5b66\u6210\u7ee9&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  english <span class=\"token keyword\">float<\/span> <span class=\"token keyword\">default<\/span> <span class=\"token number\">0.0<\/span> <span class=\"token keyword\">comment<\/span> <span class=\"token string\">&#039;\u82f1\u8bed\u6210\u7ee9&#039;<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <\/p>\n<p><span class=\"token comment\">&#8212; \u63d2\u51657\u6761\u6d4b\u8bd5\u6570\u636e<\/span><br \/>\n<span class=\"token keyword\">insert<\/span> <span class=\"token keyword\">into<\/span> exam_result <span class=\"token punctuation\">(<\/span>name<span class=\"token punctuation\">,<\/span> class<span class=\"token punctuation\">,<\/span> chinese<span class=\"token punctuation\">,<\/span> math<span class=\"token punctuation\">,<\/span> english<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">values<\/span><br \/>\n<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u5510\u4e09\u85cf&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\u4e00\u73ed&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">67<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">98<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">56<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u5b59\u609f\u7a7a&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\u4e00\u73ed&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">87<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">78<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">77<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u732a\u609f\u80fd&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\u4e00\u73ed&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">88<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">98<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">90<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u66f9\u5b5f\u5fb7&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\u4e8c\u73ed&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">82<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">84<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">67<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u5218\u7384\u5fb7&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\u4e8c\u73ed&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">55<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">85<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">45<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u5b59\u6743&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\u4e09\u73ed&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">70<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">73<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">78<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u5b8b\u516c\u660e&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\u4e09\u73ed&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">75<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">65<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">30<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>4.1 \u67e5\u6240\u6709\u5217<\/h4>\n<p><span class=\"token keyword\">select<\/span> <span class=\"token operator\">*<\/span> <span class=\"token keyword\">from<\/span> exam_result<span class=\"token punctuation\">;<\/span><\/p>\n<p>*\u4ee3\u8868\u6240\u6709\u5217&#xff0c;\u6267\u884c\u540e\u4f1a\u628a\u6574\u5f20\u8868\u7684\u6240\u6709\u884c\u6240\u6709\u5217\u90fd\u67e5\u51fa\u6765\u3002<\/p>\n<p>\u274c **\u65b0\u624b\u6ce8\u610f&#xff1a;\u6b63\u5f0f\u5de5\u4f5c\u91cc\u522b\u5199select ***<\/p>\n<li>\u8868\u5f88\u5927\u7684\u65f6\u5019&#xff0c;\u67e5\u6240\u6709\u5217\u975e\u5e38\u6162&#xff0c;\u8fd8\u4f1a\u5361\u6570\u636e\u5e93<\/li>\n<li>\u8868\u52a0\u5217\u51cf\u5217\u7684\u65f6\u5019&#xff0c;\u4ee3\u7801\u5bb9\u6613\u51fa\u95ee\u9898 \u5b9e\u9645\u5f00\u53d1\u4e2d&#xff0c;\u9700\u8981\u54ea\u5217\u5c31\u5199\u54ea\u5217<\/li>\n<h4>4.2 \u53ea\u67e5\u6307\u5b9a\u5217<\/h4>\n<p>\u60f3\u67e5\u4ec0\u4e48\u5217\u5c31\u5199\u4ec0\u4e48\u5217&#xff0c;\u5217\u7684\u987a\u5e8f\u53ef\u4ee5\u968f\u4fbf\u6362&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u53ea\u67e5\u59d3\u540d\u548c\u82f1\u8bed\u6210\u7ee9<\/span><br \/>\n<span class=\"token keyword\">select<\/span> name<span class=\"token punctuation\">,<\/span> english <span class=\"token keyword\">from<\/span> exam_result<span class=\"token punctuation\">;<\/span><\/p>\n<h4>4.3 \u7ed9\u5217\u8d77\u4e2a\u522b\u540d<\/h4>\n<p>\u5217\u540d\u592a\u957f\u6216\u8005\u662f\u8ba1\u7b97\u51fa\u6765\u7684&#xff0c;\u53ef\u4ee5\u7ed9\u5b83\u8d77\u4e2a\u597d\u61c2\u7684\u5916\u53f7&#xff0c;\u7528as\u6216\u8005\u76f4\u63a5\u7a7a\u683c\u52a0\u540d\u5b57&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u8ba1\u7b97\u4e09\u79d1\u603b\u5206&#xff0c;\u8d77\u4e2a\u522b\u540d\u53eb\u603b\u5206<\/span><br \/>\n<span class=\"token keyword\">select<\/span> name<span class=\"token punctuation\">,<\/span> chinese <span class=\"token operator\">&#043;<\/span> math <span class=\"token operator\">&#043;<\/span> english <span class=\"token keyword\">as<\/span> \u603b\u5206 <span class=\"token keyword\">from<\/span> exam_result<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u7701\u7565as&#xff0c;\u76f4\u63a5\u7a7a\u683c\u52a0\u522b\u540d&#xff0c;\u6548\u679c\u4e00\u6837<\/span><br \/>\n<span class=\"token keyword\">select<\/span> name<span class=\"token punctuation\">,<\/span> chinese <span class=\"token operator\">&#043;<\/span> math <span class=\"token operator\">&#043;<\/span> english \u603b\u5206 <span class=\"token keyword\">from<\/span> exam_result<span class=\"token punctuation\">;<\/span><\/p>\n<h4>4.4 \u6309\u6761\u4ef6\u7b5b\u9009&#xff1a;where<\/h4>\n<p>\u8fd9\u662f\u67e5\u8be2\u7684\u7075\u9b42\u3002\u8bf4\u767d\u4e86\u5c31\u662f\u53ea\u627e\u51fa\u7b26\u5408\u6761\u4ef6\u7684\u884c&#xff0c;\u6bd4\u5982\u201c\u627e\u51fa\u82f1\u8bed\u4e0d\u53ca\u683c\u7684\u540c\u5b66\u201d\u3002<\/p>\n<h5>\u5e38\u7528\u6bd4\u8f83\u8fd0\u7b97\u7b26<\/h5>\n<p>\u6bcf\u4e2a\u90fd\u914d\u4e00\u4e2a\u5c0f\u4f8b\u5b50&#xff0c;\u770b\u5b8c\u5c31\u4f1a\u7528&#xff1a;<\/p>\n<table>\n<tr>\u8fd0\u7b97\u7b26\u8bf4\u660e\u4f8b\u5b50<\/tr>\n<tbody>\n<tr>\n<td>&gt; &gt;&#061; &lt; &lt;&#061;<\/td>\n<td>\u5927\u4e8e\u3001\u5927\u4e8e\u7b49\u4e8e\u3001\u5c0f\u4e8e\u3001\u5c0f\u4e8e\u7b49\u4e8e<\/td>\n<td>select name, english from exam_result where english &lt; 60; \u67e5\u82f1\u8bed\u4e0d\u53ca\u683c\u7684<\/td>\n<\/tr>\n<tr>\n<td>&#061;<\/td>\n<td>\u7b49\u4e8e<\/td>\n<td>select name from exam_result where math &#061; 98; \u67e5\u6570\u5b66\u521a\u597d98\u5206\u7684<\/td>\n<\/tr>\n<tr>\n<td>!&#061;<\/td>\n<td>\u4e0d\u7b49\u4e8e<\/td>\n<td>select name from exam_result where math !&#061; 98; \u67e5\u6570\u5b66\u4e0d\u662f98\u5206\u7684<\/td>\n<\/tr>\n<tr>\n<td>between a and b<\/td>\n<td>\u5728a\u548cb\u4e4b\u95f4&#xff0c;\u5305\u542ba\u548cb<\/td>\n<td>select name, chinese from exam_result where chinese between 80 and 90; \u67e5\u8bed\u658780-90\u5206\u7684<\/td>\n<\/tr>\n<tr>\n<td>in (a,b,c)<\/td>\n<td>\u662f\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a<\/td>\n<td>select name, math from exam_result where math in (98, 78); \u67e5\u6570\u5b66\u662f98\u6216\u800578\u5206\u7684<\/td>\n<\/tr>\n<tr>\n<td>is null<\/td>\n<td>\u662f\u7a7a\u7684<\/td>\n<td>select name from students where qq is null; \u67e5\u6ca1\u586bqq\u53f7\u7684\u540c\u5b66<\/td>\n<\/tr>\n<tr>\n<td>is not null<\/td>\n<td>\u4e0d\u662f\u7a7a\u7684<\/td>\n<td>select name from students where qq is not null; \u67e5\u586b\u4e86qq\u53f7\u7684\u540c\u5b66<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>\u903b\u8f91\u8fd0\u7b97\u7b26<\/h5>\n<p>\u591a\u4e2a\u6761\u4ef6\u7ec4\u5408\u7684\u65f6\u5019\u7528&#xff1a;<\/p>\n<table>\n<tr>\u8fd0\u7b97\u7b26\u8bf4\u660e\u4f8b\u5b50<\/tr>\n<tbody>\n<tr>\n<td>and<\/td>\n<td>\u5e76\u4e14&#xff0c;\u4e24\u4e2a\u6761\u4ef6\u90fd\u8981\u6ee1\u8db3<\/td>\n<td>select name from exam_result where chinese &gt; 80 and math &gt; 80; \u8bed\u6587\u6570\u5b66\u90fd\u5927\u4e8e80<\/td>\n<\/tr>\n<tr>\n<td>or<\/td>\n<td>\u6216\u8005&#xff0c;\u6ee1\u8db3\u4e00\u4e2a\u5c31\u884c<\/td>\n<td>select name from exam_result where chinese &gt; 90 or math &gt; 90; \u8bed\u6587\u6216\u6570\u5b66\u6709\u4e00\u95e8\u5927\u4e8e90<\/td>\n<\/tr>\n<tr>\n<td>not<\/td>\n<td>\u4e0d\u6ee1\u8db3<\/td>\n<td>select name from exam_result where not math &#061; 98; \u6570\u5b66\u4e0d\u662f98\u5206\u7684<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u26a0\ufe0f \u65b0\u624b\u5fc5\u8e29\u5751&#xff1a;and\u4f18\u5148\u7ea7\u6bd4or\u9ad8 \u591a\u4e2a\u6761\u4ef6\u6df7\u5199\u7684\u65f6\u5019&#xff0c;\u4e00\u5b9a\u8981\u7528\u62ec\u53f7\u660e\u786e\u4f18\u5148\u7ea7\u3002<\/p>\n<p>\u9519\u8bef\u5199\u6cd5&#xff08;\u672c\u610f&#xff1a;\u8bed\u6587&gt;80&#xff0c;\u5e76\u4e14\u59d3\u5b59\u6216\u59d3\u66f9&#xff09;&#xff1a;<\/p>\n<p> <span class=\"token keyword\">select<\/span> <span class=\"token operator\">*<\/span> <span class=\"token keyword\">from<\/span> exam_result <span class=\"token keyword\">where<\/span> chinese <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">80<\/span> <span class=\"token operator\">and<\/span> name <span class=\"token operator\">like<\/span> <span class=\"token string\">&#039;\u5b59%&#039;<\/span> <span class=\"token operator\">or<\/span> name <span class=\"token operator\">like<\/span> <span class=\"token string\">&#039;\u66f9%&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5b9e\u9645\u4f1a\u53d8\u6210&#xff1a;\u300c\u8bed\u6587&gt;80\u4e14\u59d3\u5b59\u300d\u6216\u8005\u300c\u6240\u6709\u59d3\u66f9\u7684\u300d&#xff0c;\u8303\u56f4\u5b8c\u5168\u9519\u4e86\u3002<\/p>\n<p>\u6b63\u786e\u5199\u6cd5&#xff1a;<\/p>\n<p> <span class=\"token keyword\">select<\/span> <span class=\"token operator\">*<\/span> <span class=\"token keyword\">from<\/span> exam_result <span class=\"token keyword\">where<\/span> chinese <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">80<\/span> <span class=\"token operator\">and<\/span> <span class=\"token punctuation\">(<\/span>name <span class=\"token operator\">like<\/span> <span class=\"token string\">&#039;\u5b59%&#039;<\/span> <span class=\"token operator\">or<\/span> name <span class=\"token operator\">like<\/span> <span class=\"token string\">&#039;\u66f9%&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>\u6a21\u7cca\u67e5\u8be2&#xff1a;like<\/h5>\n<p>\u53ea\u8bb0\u5f97\u540d\u5b57\u91cc\u7684\u67d0\u4e2a\u5b57&#xff0c;\u5c31\u7528\u6a21\u7cca\u67e5\u8be2&#xff1a;<\/p>\n<ul>\n<li>%&#xff1a;\u5339\u914d\u4efb\u610f\u591a\u4e2a\u5b57&#xff08;\u5305\u62ec0\u4e2a&#xff09;<\/li>\n<li>_&#xff1a;\u5339\u914d\u4e25\u683c\u7684\u4e00\u4e2a\u5b57<\/li>\n<\/ul>\n<p><span class=\"token comment\">&#8212; \u627e\u6240\u6709\u59d3\u5b59\u7684\u540c\u5b66&#xff0c;\u5b59\u540e\u9762\u6709\u591a\u5c11\u5b57\u90fd\u884c<\/span><br \/>\n<span class=\"token keyword\">select<\/span> name <span class=\"token keyword\">from<\/span> exam_result <span class=\"token keyword\">where<\/span> name <span class=\"token operator\">like<\/span> <span class=\"token string\">&#039;\u5b59%&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u627e\u540d\u5b57\u662f\u4e24\u4e2a\u5b57\u3001\u59d3\u5b59\u7684\u540c\u5b66&#xff0c;\u5b59\u540e\u9762\u53ea\u80fd\u6709\u4e00\u4e2a\u5b57<\/span><br \/>\n<span class=\"token keyword\">select<\/span> name <span class=\"token keyword\">from<\/span> exam_result <span class=\"token keyword\">where<\/span> name <span class=\"token operator\">like<\/span> <span class=\"token string\">&#039;\u5b59_&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>\u26a0\ufe0f \u8d85\u7ea7\u5927\u5751&#xff1a;null\u4e0d\u80fd\u7528&#061;\u5224\u65ad<\/h5>\n<p>\u8fd9\u662f90%\u7684\u65b0\u624b\u7b2c\u4e00\u6b21\u90fd\u4f1a\u5199\u9519\u7684\u3002<\/p>\n<p>mysql\u91cc\u7684null\u662f\u300c\u4e0d\u77e5\u9053\u3001\u4e0d\u786e\u5b9a\u300d\u7684\u610f\u601d&#xff0c;\u4e0d\u662f0&#xff0c;\u4e5f\u4e0d\u662f\u7a7a\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u9519\u8bef\u5199\u6cd5&#xff0c;\u6c38\u8fdc\u67e5\u4e0d\u5230\u7ed3\u679c&#xff1a;<\/p>\n<p><span class=\"token keyword\">select<\/span> name<span class=\"token punctuation\">,<\/span> qq <span class=\"token keyword\">from<\/span> students <span class=\"token keyword\">where<\/span> qq <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">null<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u6b63\u786e\u5199\u6cd5&#xff1a;<\/p>\n<p><span class=\"token keyword\">select<\/span> name<span class=\"token punctuation\">,<\/span> qq <span class=\"token keyword\">from<\/span> students <span class=\"token keyword\">where<\/span> qq <span class=\"token operator\">is<\/span> <span class=\"token boolean\">null<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u65b0\u624b\u8bb0\u4f4f&#xff1a;\u5224\u65ad\u662f\u4e0d\u662fnull&#xff0c;\u56fa\u5b9a\u7528is null\u6216\u8005is not null&#xff0c;\u522b\u7528\u7b49\u53f7\u3002<\/p>\n<h4>4.5 \u65b0\u624b\u9ad8\u9891\u62a5\u9519&#xff1a;where\u91cc\u7528\u522b\u540d<\/h4>\n<p>\u8fd9\u4e5f\u662f\u5165\u95e8\u5fc5\u8e29\u7684\u5751&#xff0c;\u5148\u770b\u9519\u8bef\u5199\u6cd5&#xff1a;<\/p>\n<p><span class=\"token keyword\">select<\/span> name<span class=\"token punctuation\">,<\/span> chinese<span class=\"token operator\">&#043;<\/span>math<span class=\"token operator\">&#043;<\/span>english total<br \/>\n<span class=\"token keyword\">from<\/span> exam_result<br \/>\n<span class=\"token keyword\">where<\/span> total <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">200<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u62a5\u9519&#xff1a;unknown column &#039;total&#039; in &#039;where clause&#039;<\/p>\n<p>\u5927\u767d\u8bdd\u539f\u56e0&#xff1a;mysql\u6267\u884c\u7684\u65f6\u5019&#xff0c;\u5148\u6267\u884cwhere\u7b5b\u9009&#xff0c;\u540e\u6267\u884cselect\u8ba1\u7b97\u522b\u540d\u3002\u7b49where\u7b5b\u9009\u7684\u65f6\u5019&#xff0c;total\u8fd9\u4e2a\u5916\u53f7\u8fd8\u6ca1\u8d77\u597d&#xff0c;\u6240\u4ee5\u4e0d\u8ba4\u3002<\/p>\n<p>\u4e09\u79cd\u6b63\u786e\u5199\u6cd5&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u5199\u6cd51&#xff1a;\u628a\u8868\u8fbe\u5f0f\u539f\u6837\u5199\u4e00\u904d&#xff0c;\u63a8\u8350\u8fd9\u4e48\u5199&#xff0c;\u6027\u80fd\u6700\u597d<\/span><br \/>\n<span class=\"token keyword\">select<\/span> name<span class=\"token punctuation\">,<\/span> chinese<span class=\"token operator\">&#043;<\/span>math<span class=\"token operator\">&#043;<\/span>english total<br \/>\n<span class=\"token keyword\">from<\/span> exam_result<br \/>\n<span class=\"token keyword\">where<\/span> chinese<span class=\"token operator\">&#043;<\/span>math<span class=\"token operator\">&#043;<\/span>english <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">200<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u5199\u6cd52&#xff1a;\u7528having\u4ee3\u66ffwhere&#xff0c;\u7b80\u5355\u67e5\u8be2\u53ef\u4ee5\u51d1\u5408\u7528<\/span><br \/>\n<span class=\"token keyword\">select<\/span> name<span class=\"token punctuation\">,<\/span> chinese<span class=\"token operator\">&#043;<\/span>math<span class=\"token operator\">&#043;<\/span>english total<br \/>\n<span class=\"token keyword\">from<\/span> exam_result<br \/>\n<span class=\"token keyword\">having<\/span> total <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">200<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u5199\u6cd53&#xff1a;\u7528\u5b50\u67e5\u8be2\u5305\u4e00\u5c42&#xff0c;\u590d\u6742\u67e5\u8be2\u901a\u7528<\/span><br \/>\n<span class=\"token keyword\">select<\/span> name<span class=\"token punctuation\">,<\/span> total<br \/>\n<span class=\"token keyword\">from<\/span> <span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token keyword\">select<\/span> name<span class=\"token punctuation\">,<\/span> chinese<span class=\"token operator\">&#043;<\/span>math<span class=\"token operator\">&#043;<\/span>english total<br \/>\n    <span class=\"token keyword\">from<\/span> exam_result<br \/>\n<span class=\"token punctuation\">)<\/span> t<br \/>\n<span class=\"token keyword\">where<\/span> total <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">200<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>4.6 \u6392\u5e8f&#xff1a;order by<\/h4>\n<p>\u67e5\u51fa\u6765\u7684\u6570\u636e\u592a\u4e71&#xff1f;\u6309\u6307\u5b9a\u5217\u6392\u4e2a\u5e8f\u3002<\/p>\n<ul>\n<li>asc&#xff1a;\u5347\u5e8f&#xff0c;\u4ece\u5c0f\u5230\u5927&#xff0c;\u9ed8\u8ba4\u5c31\u662f\u8fd9\u4e2a<\/li>\n<li>desc&#xff1a;\u964d\u5e8f&#xff0c;\u4ece\u5927\u5230\u5c0f<\/li>\n<\/ul>\n<p><span class=\"token comment\">&#8212; \u6309\u6570\u5b66\u6210\u7ee9\u4ece\u4f4e\u5230\u9ad8\u6392<\/span><br \/>\n<span class=\"token keyword\">select<\/span> name<span class=\"token punctuation\">,<\/span> math <span class=\"token keyword\">from<\/span> exam_result <span class=\"token keyword\">order<\/span> <span class=\"token keyword\">by<\/span> math<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u6309\u603b\u5206\u4ece\u9ad8\u5230\u4f4e\u6392&#xff0c;\u53ef\u4ee5\u7528\u522b\u540d<\/span><br \/>\n<span class=\"token keyword\">select<\/span> name<span class=\"token punctuation\">,<\/span> chinese <span class=\"token operator\">&#043;<\/span> math <span class=\"token operator\">&#043;<\/span> english \u603b\u5206 <span class=\"token keyword\">from<\/span> exam_result <span class=\"token keyword\">order<\/span> <span class=\"token keyword\">by<\/span> \u603b\u5206 <span class=\"token keyword\">desc<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u4e5f\u53ef\u4ee5\u6309\u591a\u5217\u6392\u5e8f&#xff0c;\u5148\u6309\u524d\u9762\u7684\u6392&#xff0c;\u524d\u9762\u76f8\u540c\u518d\u6309\u540e\u9762\u7684\u6392&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u5148\u6309\u6570\u5b66\u964d\u5e8f&#xff0c;\u6570\u5b66\u5206\u6570\u4e00\u6837\u7684\u8bdd&#xff0c;\u518d\u6309\u82f1\u8bed\u5347\u5e8f<\/span><br \/>\n<span class=\"token keyword\">select<\/span> name<span class=\"token punctuation\">,<\/span> math<span class=\"token punctuation\">,<\/span> english <span class=\"token keyword\">from<\/span> exam_result<br \/>\n<span class=\"token keyword\">order<\/span> <span class=\"token keyword\">by<\/span> math <span class=\"token keyword\">desc<\/span><span class=\"token punctuation\">,<\/span> english <span class=\"token keyword\">asc<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>4.7 \u5206\u9875&#xff1a;limit<\/h4>\n<p>\u6570\u636e\u592a\u591a\u4e00\u6b21\u770b\u4e0d\u5b8c&#xff0c;\u4e00\u9875\u4e00\u9875\u770b\u3002<\/p>\n<p>\u4e24\u79cd\u5e38\u7528\u5199\u6cd5&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u76f4\u63a5\u53d6\u524d3\u6761<\/span><br \/>\n<span class=\"token keyword\">select<\/span> id<span class=\"token punctuation\">,<\/span> name <span class=\"token keyword\">from<\/span> exam_result <span class=\"token keyword\">limit<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u4ece\u7b2c0\u6761\u5f00\u59cb&#xff0c;\u53d63\u6761&#xff08;\u7b2c1\u9875&#xff09;<\/span><br \/>\n<span class=\"token keyword\">select<\/span> id<span class=\"token punctuation\">,<\/span> name <span class=\"token keyword\">from<\/span> exam_result <span class=\"token keyword\">limit<\/span> <span class=\"token number\">3<\/span> <span class=\"token keyword\">offset<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u4ece\u7b2c3\u6761\u5f00\u59cb&#xff0c;\u53d63\u6761&#xff08;\u7b2c2\u9875&#xff09;<\/span><br \/>\n<span class=\"token keyword\">select<\/span> id<span class=\"token punctuation\">,<\/span> name <span class=\"token keyword\">from<\/span> exam_result <span class=\"token keyword\">limit<\/span> <span class=\"token number\">3<\/span> <span class=\"token keyword\">offset<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u65b0\u624b\u6ce8\u610f&#xff1a;offset\u662f\u4ece0\u5f00\u59cb\u6570\u7684&#xff0c;\u4e0d\u662f\u4ece1\u5f00\u59cb\u3002 \u597d\u4e60\u60ef&#xff1a;\u67e5\u4e0d\u719f\u6089\u7684\u8868&#xff0c;\u5148\u52a0\u4e2alimit 1\u8bd5\u8bd5&#xff0c;\u9632\u6b62\u8868\u592a\u5927\u628a\u6570\u636e\u5e93\u67e5\u5361\u6b7b\u3002<\/p>\n<hr \/>\n<h3>\u4e94\u3001update&#xff1a;\u4fee\u6539\u8868\u91cc\u7684\u6570\u636e<\/h3>\n<p>\u8bf4\u767d\u4e86\u5c31\u662f\u4fee\u6539\u8868\u683c\u91cc\u5df2\u6709\u7684\u5185\u5bb9&#xff0c;\u6bd4\u5982\u540c\u5b66\u6210\u7ee9\u767b\u9519\u4e86\u8981\u6539\u3002<\/p>\n<h4>5.1 \u4fee\u6539\u6307\u5b9a\u884c<\/h4>\n<p>\u6bd4\u5982\u628a\u5b59\u609f\u7a7a\u7684\u6570\u5b66\u6210\u7ee9\u6539\u621080\u5206&#xff1a;<\/p>\n<p><span class=\"token keyword\">update<\/span> exam_result <span class=\"token keyword\">set<\/span> math <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">80<\/span> <span class=\"token keyword\">where<\/span> name <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;\u5b59\u609f\u7a7a&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u4e00\u6b21\u6539\u591a\u5217\u4e5f\u53ef\u4ee5&#xff1a;<\/p>\n<p><span class=\"token keyword\">update<\/span> exam_result <span class=\"token keyword\">set<\/span> math <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">60<\/span><span class=\"token punctuation\">,<\/span> chinese <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">70<\/span> <span class=\"token keyword\">where<\/span> name <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;\u66f9\u5b5f\u5fb7&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u4e5f\u53ef\u4ee5\u5728\u539f\u6765\u7684\u57fa\u7840\u4e0a\u6539&#xff0c;\u6bd4\u5982\u7ed9\u5012\u6570\u4e09\u540d\u7684\u6570\u5b66\u52a030\u5206&#xff1a;<\/p>\n<p><span class=\"token keyword\">update<\/span> exam_result <span class=\"token keyword\">set<\/span> math <span class=\"token operator\">&#061;<\/span> math <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">30<\/span><br \/>\n<span class=\"token keyword\">order<\/span> <span class=\"token keyword\">by<\/span> chinese <span class=\"token operator\">&#043;<\/span> math <span class=\"token operator\">&#043;<\/span> english <span class=\"token keyword\">limit<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u6ce8\u610f&#xff1a;mysql\u4e0d\u652f\u6301math &#043;&#061; 30\u8fd9\u79cd\u7b80\u5199&#xff0c;\u5fc5\u987b\u5199math &#061; math &#043; 30\u3002<\/p>\n<h4>5.2 \u2757\ufe0f \u81f4\u547d\u63d0\u9192&#xff1a;\u5343\u4e07\u522b\u5fd8\u5199where<\/h4>\n<p><span class=\"token comment\">&#8212; \u8fd9\u884c\u4f1a\u628a\u5168\u8868\u6240\u6709\u4eba\u7684\u8bed\u6587\u6210\u7ee9\u90fd\u6539\u62100&#xff01;<\/span><br \/>\n<span class=\"token keyword\">update<\/span> exam_result <span class=\"token keyword\">set<\/span> chinese <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd9\u662f\u6570\u636e\u5e93\u6700\u7ecf\u5178\u7684\u4e8b\u6545&#xff0c;\u6ca1\u6709\u4e4b\u4e00\u3002\u5fd8\u5199where\u5c31\u4f1a\u66f4\u65b0\u5168\u8868&#xff0c;\u6570\u636e\u6bc1\u4e86\u5f88\u96be\u6062\u590d\u3002<\/p>\n<p>\u5b89\u5168\u5c0f\u6280\u5de7&#xff1a; \u6539\u6570\u636e\u524d&#xff0c;\u5148\u628awhere\u6761\u4ef6\u590d\u5236\u5230select\u91cc\u67e5\u4e00\u904d&#xff0c;\u786e\u8ba4\u662f\u4f60\u8981\u6539\u7684\u90a3\u4e9b\u884c&#xff0c;\u518d\u6267\u884cupdate\u3002<\/p>\n<h4>5.3 \u66f4\u65b0\u907f\u5751<\/h4>\n<li>\u6c38\u8fdc\u8bb0\u5f97\u52a0where\u6761\u4ef6<\/li>\n<li>\u5b57\u7b26\u4e32\u503c\u52a0\u5355\u5f15\u53f7<\/li>\n<li>\u5927\u8868\u6279\u91cf\u66f4\u65b0\u5c3d\u91cf\u5206\u6279&#xff0c;\u522b\u4e00\u6b21\u6027\u9501\u5168\u8868<\/li>\n<hr \/>\n<h3>\u516d\u3001delete&#xff1a;\u5220\u9664\u8868\u91cc\u7684\u6570\u636e<\/h3>\n<p>\u5c31\u662f\u5220\u6389\u8868\u683c\u91cc\u7684\u884c&#xff0c;\u6bd4\u5982\u540c\u5b66\u9000\u5b66\u4e86\u4ece\u82b1\u540d\u518c\u91cc\u79fb\u9664\u3002<\/p>\n<h4>6.1 \u5220\u9664\u6307\u5b9a\u884c<\/h4>\n<p>\u6bd4\u5982\u5220\u6389\u5b59\u609f\u7a7a\u7684\u6210\u7ee9&#xff1a;<\/p>\n<p><span class=\"token keyword\">delete<\/span> <span class=\"token keyword\">from<\/span> exam_result <span class=\"token keyword\">where<\/span> name <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;\u5b59\u609f\u7a7a&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>6.2 \u2757\ufe0f \u81f4\u547d\u63d0\u9192&#xff1a;\u5343\u4e07\u522b\u5fd8\u5199where<\/h4>\n<p>\u548cupdate\u4e00\u6837&#xff0c;\u4e0d\u52a0where\u4f1a\u5220\u6389\u5168\u8868\u6240\u6709\u6570\u636e&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u6e05\u7a7a\u6574\u5f20\u8868&#xff0c;\u975e\u5e38\u5371\u9669<\/span><br \/>\n<span class=\"token keyword\">delete<\/span> <span class=\"token keyword\">from<\/span> exam_result<span class=\"token punctuation\">;<\/span><\/p>\n<h4>6.3 \u6e05\u7a7a\u5168\u8868\u7684\u53e6\u4e00\u79cd\u65b9\u5f0f&#xff1a;truncate<\/h4>\n<p>\u60f3\u5feb\u901f\u6e05\u7a7a\u6574\u5f20\u8868&#xff0c;\u7528truncate\u6bd4delete\u5feb\u5f97\u591a&#xff1a;<\/p>\n<p><span class=\"token keyword\">truncate<\/span> <span class=\"token keyword\">table<\/span> exam_result<span class=\"token punctuation\">;<\/span><\/p>\n<h4>6.4 delete\u548ctruncate\u7684\u533a\u522b<\/h4>\n<p>\u5927\u767d\u8bdd\u603b\u7ed3\u4e00\u4e0b&#xff1a;<\/p>\n<table>\n<tr>\u5bf9\u6bd4\u9879deletetruncate<\/tr>\n<tbody>\n<tr>\n<td>\u80fd\u4e0d\u80fd\u5220\u90e8\u5206\u884c<\/td>\n<td>\u80fd&#xff0c;\u52a0where\u5c31\u884c<\/td>\n<td>\u4e0d\u80fd&#xff0c;\u53ea\u80fd\u6e05\u7a7a\u5168\u8868<\/td>\n<\/tr>\n<tr>\n<td>\u5220\u9519\u4e86\u80fd\u4e0d\u80fd\u6062\u590d<\/td>\n<td>\u80fd&#xff0c;\u4e8b\u52a1\u91cc\u53ef\u4ee5\u56de\u6eda<\/td>\n<td>\u4e0d\u80fd&#xff0c;\u5220\u4e86\u5c31\u6ca1\u4e86<\/td>\n<\/tr>\n<tr>\n<td>\u901f\u5ea6<\/td>\n<td>\u6162&#xff0c;\u9010\u884c\u5220&#xff0c;\u5927\u8868\u7279\u522b\u6162<\/td>\n<td>\u6781\u5feb&#xff0c;\u76f4\u63a5\u6254\u6389\u6574\u5f20\u8868\u518d\u65b0\u5efa<\/td>\n<\/tr>\n<tr>\n<td>\u81ea\u589eid<\/td>\n<td>\u4e0d\u91cd\u7f6e&#xff0c;\u63a5\u7740\u539f\u6765\u7684\u53f7\u7ee7\u7eed<\/td>\n<td>\u91cd\u7f6e&#xff0c;\u4ece1\u91cd\u65b0\u5f00\u59cb<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u603b\u7ed3&#xff1a;\u5220\u90e8\u5206\u6570\u636e\u7528delete&#xff1b;\u786e\u5b9a\u8981\u6e05\u7a7a\u5168\u8868\u3001\u4e0d\u9700\u8981\u6062\u590d&#xff0c;\u7528truncate\u3002<\/p>\n<hr \/>\n<h3>\u4e03\u3001\u5206\u7ec4\u7edf\u8ba1&#xff1a;\u805a\u5408\u51fd\u6570 &#043; group by<\/h3>\n<p>\u5149\u67e5\u5355\u884c\u6570\u636e\u4e0d\u591f&#xff0c;\u6211\u4eec\u7ecf\u5e38\u8981\u505a\u7edf\u8ba1&#xff0c;\u6bd4\u5982\u201c\u6bcf\u4e2a\u73ed\u7684\u5e73\u5747\u5206\u201d\u201c\u6bcf\u4e2a\u73ed\u6709\u591a\u5c11\u4eba\u201d&#xff0c;\u8fd9\u5c31\u7528\u5230group by\u5206\u7ec4\u7edf\u8ba1\u4e86\u3002<\/p>\n<h4>7.1 \u4e94\u4e2a\u5e38\u7528\u805a\u5408\u51fd\u6570<\/h4>\n<p>\u8bf4\u767d\u4e86\u5c31\u662f\u628a\u4e00\u5806\u6570\u636e\u7b97\u6210\u4e00\u4e2a\u7ed3\u679c&#xff0c;\u6bd4\u5982\u6c42\u548c\u3001\u6c42\u5e73\u5747\u3002<\/p>\n<table>\n<tr>\u51fd\u6570\u5927\u767d\u8bdd\u8bf4\u660e\u4f8b\u5b50<\/tr>\n<tbody>\n<tr>\n<td>count(*)<\/td>\n<td>\u7edf\u8ba1\u4e00\u5171\u6709\u591a\u5c11\u884c<\/td>\n<td>select count(*) from exam_result; \u7edf\u8ba1\u73ed\u7ea7\u603b\u4eba\u6570<\/td>\n<\/tr>\n<tr>\n<td>sum(\u5217)<\/td>\n<td>\u6c42\u548c&#xff0c;\u628a\u8fd9\u4e00\u5217\u6240\u6709\u6570\u52a0\u8d77\u6765<\/td>\n<td>select sum(math) from exam_result; \u7b97\u6570\u5b66\u6210\u7ee9\u603b\u5206<\/td>\n<\/tr>\n<tr>\n<td>avg(\u5217)<\/td>\n<td>\u6c42\u5e73\u5747\u503c<\/td>\n<td>select avg(english) from exam_result; \u7b97\u82f1\u8bed\u5e73\u5747\u5206<\/td>\n<\/tr>\n<tr>\n<td>max(\u5217)<\/td>\n<td>\u6c42\u6700\u5927\u503c<\/td>\n<td>select max(chinese) from exam_result; \u627e\u8bed\u6587\u6700\u9ad8\u5206<\/td>\n<\/tr>\n<tr>\n<td>min(\u5217)<\/td>\n<td>\u6c42\u6700\u5c0f\u503c<\/td>\n<td>select min(math) from exam_result; \u627e\u6570\u5b66\u6700\u4f4e\u5206<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>7.2 group by\u5230\u5e95\u5728\u5e72\u561b&#xff1f;<\/h4>\n<p>\u4f60\u53ef\u4ee5\u628agroup by\u7406\u89e3\u6210\u7ed9\u6570\u636e\u6253\u5305\u88c5\u888b\u3001\u6309\u5806\u5206\u7c7b\u3002<\/p>\n<p>\u6ca1\u5206\u7ec4\u7684\u65f6\u5019&#xff0c;\u4f60\u9762\u5bf9\u7684\u662f\u4e00\u884c\u4e00\u884c\u7684\u5b66\u751f&#xff0c;\u53ef\u4ee5\u67e5\u67d0\u4e2a\u4eba\u7684\u6210\u7ee9\u3002 \u6267\u884cgroup by class\u4e4b\u540e&#xff0c;\u6570\u636e\u4f1a\u6309\u73ed\u7ea7\u6253\u5305\u6210\u4e00\u4e2a\u4e2a\u72ec\u7acb\u7684\u5c0f\u7ec4&#xff1a;<\/p>\n<ul>\n<li>\u4e00\u73ed\u4e00\u888b&#xff0c;\u91cc\u9762\u88c5\u7740\u4e00\u73ed\u6240\u6709\u540c\u5b66\u7684\u8bb0\u5f55<\/li>\n<li>\u4e8c\u73ed\u4e00\u888b&#xff0c;\u91cc\u9762\u88c5\u7740\u4e8c\u73ed\u6240\u6709\u540c\u5b66\u7684\u8bb0\u5f55<\/li>\n<li>\u4e09\u73ed\u4e00\u888b&#xff0c;\u91cc\u9762\u88c5\u7740\u4e09\u73ed\u6240\u6709\u540c\u5b66\u7684\u8bb0\u5f55<\/li>\n<\/ul>\n<p>\u6838\u5fc3\u53d8\u5316&#xff1a;\u5206\u7ec4\u4e4b\u540e&#xff0c;\u4f60\u9762\u5bf9\u7684\u6700\u5c0f\u5355\u4f4d&#xff0c;\u4ece\u300c\u5355\u4e2a\u5b66\u751f\u300d\u53d8\u6210\u4e86\u300c\u6574\u4e2a\u73ed\u7ea7\u300d\u3002 \u4f60\u4e0d\u80fd\u518d\u76f4\u63a5\u95ee\u201c\u8fd9\u4e2a\u7ec4\u91cc\u5b66\u751f\u53eb\u4ec0\u4e48\u540d\u5b57\u201d&#xff0c;\u56e0\u4e3a\u4e00\u4e2a\u7ec4\u91cc\u6709\u597d\u591a\u5b66\u751f&#xff1b;\u4f60\u53ea\u80fd\u95ee\u201c\u8fd9\u4e2a\u73ed\u6709\u591a\u5c11\u4eba\u201d\u201c\u8fd9\u4e2a\u73ed\u5e73\u5747\u5206\u591a\u5c11\u201d\u8fd9\u79cd\u9488\u5bf9\u6574\u4e2a\u7ec4\u7684\u95ee\u9898\u3002<\/p>\n<h4>7.3 \u57fa\u672c\u7528\u6cd5&#xff1a;\u5206\u7ec4 &#043; \u805a\u5408<\/h4>\n<p>\u5206\u7ec4\u5fc5\u987b\u548c\u805a\u5408\u51fd\u6570\u642d\u914d\u7528\u3002\u805a\u5408\u51fd\u6570\u5c31\u662f\u4e13\u95e8\u7528\u6765\u300c\u628a\u4e00\u7ec4\u6570\u636e\u7b97\u6210\u4e00\u4e2a\u6570\u300d\u7684&#xff0c;\u521a\u597d\u5bf9\u5e94\u5206\u7ec4\u540e\u7684\u7ec4\u7ea7\u8ba1\u7b97\u3002<\/p>\n<h5>\u4f8b1&#xff1a;\u7edf\u8ba1\u6bcf\u4e2a\u73ed\u6709\u591a\u5c11\u4eba<\/h5>\n<p><span class=\"token keyword\">select<\/span> class<span class=\"token punctuation\">,<\/span> <span class=\"token function\">count<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> \u4eba\u6570<br \/>\n<span class=\"token keyword\">from<\/span> exam_result<br \/>\n<span class=\"token keyword\">group<\/span> <span class=\"token keyword\">by<\/span> class<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p>&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8211;&#043;<br \/>\n| class  | \u4eba\u6570   |<br \/>\n&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8211;&#043;<br \/>\n| \u4e00\u73ed   |      3 |<br \/>\n| \u4e8c\u73ed   |      2 |<br \/>\n| \u4e09\u73ed   |      2 |<br \/>\n&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8211;&#043;<\/p>\n<h5>\u4f8b2&#xff1a;\u7edf\u8ba1\u6bcf\u4e2a\u73ed\u7684\u6570\u5b66\u6210\u7ee9\u60c5\u51b5<\/h5>\n<p><span class=\"token keyword\">select<\/span><br \/>\n  class<span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token function\">avg<\/span><span class=\"token punctuation\">(<\/span>math<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> \u6570\u5b66\u5e73\u5747\u5206<span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token function\">max<\/span><span class=\"token punctuation\">(<\/span>math<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> \u6570\u5b66\u6700\u9ad8\u5206<span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token function\">min<\/span><span class=\"token punctuation\">(<\/span>math<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> \u6570\u5b66\u6700\u4f4e\u5206<br \/>\n<span class=\"token keyword\">from<\/span> exam_result<br \/>\n<span class=\"token keyword\">group<\/span> <span class=\"token keyword\">by<\/span> class<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p>&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<br \/>\n| class  | \u6570\u5b66\u5e73\u5747\u5206   | \u6570\u5b66\u6700\u9ad8\u5206   | \u6570\u5b66\u6700\u4f4e\u5206   |<br \/>\n&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<br \/>\n| \u4e00\u73ed   |      91.333 |           98 |           78 |<br \/>\n| \u4e8c\u73ed   |      84.500 |           85 |           84 |<br \/>\n| \u4e09\u73ed   |      69.000 |           73 |           65 |<br \/>\n&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<\/p>\n<h5>\u4f8b3&#xff1a;\u591a\u5b57\u6bb5\u5206\u7ec4<\/h5>\n<p>group by\u540e\u9762\u53ef\u4ee5\u8ddf\u591a\u4e2a\u5b57\u6bb5&#xff0c;\u5c31\u662f\u6309\u591a\u4e2a\u7ef4\u5ea6\u5c42\u5c42\u7ec6\u5206\u3002 \u6bd4\u5982\u6309\u73ed\u7ea7&#043;\u6027\u522b\u5206\u7ec4&#xff08;\u5047\u8bbe\u6709gender\u5b57\u6bb5&#xff09;&#xff1a;<\/p>\n<p><span class=\"token keyword\">select<\/span> class<span class=\"token punctuation\">,<\/span> gender<span class=\"token punctuation\">,<\/span> <span class=\"token function\">count<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">from<\/span> exam_result<br \/>\n<span class=\"token keyword\">group<\/span> <span class=\"token keyword\">by<\/span> class<span class=\"token punctuation\">,<\/span> gender<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5c31\u662f\u5148\u6309\u73ed\u7ea7\u5206&#xff0c;\u6bcf\u4e2a\u73ed\u91cc\u518d\u6309\u6027\u522b\u5206&#xff0c;\u7edf\u8ba1\u6bcf\u4e2a\u73ed\u6bcf\u4e2a\u6027\u522b\u7684\u4eba\u6570\u3002<\/p>\n<h4>7.4 \u65b0\u624b\u7075\u9b42\u62f7\u95ee&#xff1a;\u5206\u5b8c\u7ec4&#xff0c;\u539f\u59cb\u884c\u8fd8\u5728\u5417&#xff1f;<\/h4>\n<p>\u78c1\u76d8\u4e0a\u7684\u539f\u8868&#xff1a;\u5b8c\u5b8c\u6574\u6574\u8fd8\u5728&#xff0c;\u4e00\u70b9\u6ca1\u52a8\u3002 group by\u53ea\u662f\u8bfb\u53d6\u6570\u636e\u505a\u8ba1\u7b97&#xff0c;\u5c5e\u4e8e\u67e5\u8be2\u64cd\u4f5c&#xff0c;\u4e0d\u4f1a\u4fee\u6539\u3001\u5220\u9664\u539f\u8868\u91cc\u7684\u4efb\u4f55\u6570\u636e\u3002<\/p>\n<p>\u8fd9\u6761\u67e5\u8be2\u8fd4\u56de\u7684\u7ed3\u679c\u91cc&#xff1a;\u539f\u59cb\u660e\u7ec6\u88ab\u538b\u7f29\u4e86&#xff0c;\u770b\u4e0d\u5230\u7ec4\u5185\u6bcf\u4e00\u884c\u3002 \u5c31\u50cf\u6253\u5305\u4e4b\u540e&#xff0c;\u4f60\u53ea\u80fd\u770b\u5230\u888b\u5b50\u5916\u9762\u5199\u7684\u201c\u603b\u91cd\u91cf\u3001\u603b\u4e2a\u6570\u201d&#xff0c;\u770b\u4e0d\u5230\u888b\u5b50\u91cc\u6bcf\u4e00\u4e2a\u6c34\u679c\u3002<\/p>\n<p>\u8fd9\u4e5f\u662f\u65b0\u624b\u6700\u5e38\u89c1\u62a5\u9519\u7684\u6839\u6e90&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u9519\u8bef\u5199\u6cd5&#xff0c;mysql 5.7&#043;\u9ed8\u8ba4\u76f4\u63a5\u62a5\u9519<\/span><br \/>\n<span class=\"token keyword\">select<\/span> class<span class=\"token punctuation\">,<\/span> name <span class=\"token keyword\">from<\/span> exam_result <span class=\"token keyword\">group<\/span> <span class=\"token keyword\">by<\/span> class<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u539f\u56e0&#xff1a;\u5206\u7ec4\u540e\u6bcf\u4e2a\u73ed\u6709\u597d\u51e0\u4e2aname&#xff0c;\u6570\u636e\u5e93\u4e0d\u77e5\u9053\u8be5\u8fd4\u56de\u54ea\u4e00\u4e2a&#xff0c;\u6240\u4ee5\u76f4\u63a5\u62d2\u7edd\u3002 \u65e7\u7248\u672c\u5173\u95ed\u4e25\u683c\u6a21\u5f0f\u540e\u4f1a\u968f\u673a\u8fd4\u56de\u4e00\u4e2aname&#xff0c;\u7ed3\u679c\u4e0d\u53ef\u63a7&#xff0c;\u4e1a\u52a1\u91cc\u7edd\u5bf9\u4e0d\u80fd\u7528\u3002<\/p>\n<h4>7.5 \u60f3\u8981\u660e\u7ec6 &#043; \u5206\u7ec4\u7edf\u8ba1&#xff1f;\u7528\u7a97\u53e3\u51fd\u6570<\/h4>\n<p>\u5982\u679c\u65e2\u60f3\u4fdd\u7559\u6240\u6709\u539f\u59cb\u5b66\u751f\u660e\u7ec6&#xff0c;\u53c8\u60f3\u770b\u5230\u6bcf\u4e2a\u73ed\u7684\u5e73\u5747\u5206&#xff0c;group by\u505a\u4e0d\u5230&#xff0c;\u8981\u7528\u7a97\u53e3\u51fd\u6570partition by\u3002<\/p>\n<p>\u7b80\u5355\u5bf9\u6bd4&#xff1a;<\/p>\n<ul>\n<li>group by class&#xff1a;\u538b\u7f29\u5206\u7ec4&#xff0c;\u6bcf\u7ec4\u53ea\u8f93\u51fa1\u884c\u7edf\u8ba1\u7ed3\u679c&#xff0c;\u539f\u59cb\u660e\u7ec6\u4e0d\u5728\u7ed3\u679c\u91cc<\/li>\n<li>partition by class&#xff1a;\u4e0d\u538b\u7f29\u5206\u7ec4&#xff0c;\u6240\u6709\u539f\u59cb\u884c\u5168\u90e8\u4fdd\u7559&#xff0c;\u6bcf\u4e00\u884c\u90fd\u9644\u5e26\u672c\u7ec4\u7684\u7edf\u8ba1\u503c<\/li>\n<\/ul>\n<p>\u793a\u4f8b&#xff08;\u4e86\u89e3\u5373\u53ef&#xff0c;\u5c5e\u4e8e\u8fdb\u9636\u5185\u5bb9&#xff09;&#xff1a;<\/p>\n<p><span class=\"token keyword\">select<\/span><br \/>\n  class<span class=\"token punctuation\">,<\/span> name<span class=\"token punctuation\">,<\/span> math<span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token function\">avg<\/span><span class=\"token punctuation\">(<\/span>math<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">over<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">partition<\/span> <span class=\"token keyword\">by<\/span> class<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> \u73ed\u7ea7\u5e73\u5747\u5206<br \/>\n<span class=\"token keyword\">from<\/span> exam_result<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8f93\u51fa\u6548\u679c&#xff1a;<\/p>\n<p>&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#043;&#8212;&#8212;&#8212;&#8212;&#043;<br \/>\n| class  | name   | math | \u73ed\u7ea7\u5e73\u5747\u5206 |<br \/>\n&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#043;&#8212;&#8212;&#8212;&#8212;&#043;<br \/>\n| \u4e00\u73ed   | \u5510\u4e09\u85cf |   98 |      91.33 |<br \/>\n| \u4e00\u73ed   | \u5b59\u609f\u7a7a |   78 |      91.33 |<br \/>\n| \u4e00\u73ed   | \u732a\u609f\u80fd |   98 |      91.33 |<br \/>\n| \u4e8c\u73ed   | \u66f9\u5b5f\u5fb7 |   84 |      84.50 |<br \/>\n| \u4e8c\u73ed   | \u5218\u7384\u5fb7 |   85 |      84.50 |<br \/>\n| \u4e09\u73ed   | \u5b59\u6743   |   73 |      69.00 |<br \/>\n| \u4e09\u73ed   | \u5b8b\u516c\u660e |   65 |      69.00 |<br \/>\n&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#043;&#8212;&#8212;&#8212;&#8212;&#043;<\/p>\n<h4>7.6 having&#xff1a;\u5206\u7ec4\u540e\u7b5b\u9009<\/h4>\n<p>\u5206\u7ec4\u5b8c\u4e86&#xff0c;\u60f3\u628a\u4e0d\u7b26\u5408\u6761\u4ef6\u7684\u6574\u4e2a\u7ec4\u53bb\u6389&#xff0c;\u7528having\u3002<\/p>\n<p>\u6bd4\u5982\u627e\u51fa\u6570\u5b66\u5e73\u5747\u5206\u5927\u4e8e80\u7684\u73ed\u7ea7&#xff1a;<\/p>\n<p><span class=\"token keyword\">select<\/span> class<span class=\"token punctuation\">,<\/span> <span class=\"token function\">avg<\/span><span class=\"token punctuation\">(<\/span>math<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> \u6570\u5b66\u5e73\u5747\u5206<br \/>\n<span class=\"token keyword\">from<\/span> exam_result<br \/>\n<span class=\"token keyword\">group<\/span> <span class=\"token keyword\">by<\/span> class<br \/>\n<span class=\"token keyword\">having<\/span> <span class=\"token function\">avg<\/span><span class=\"token punctuation\">(<\/span>math<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">80<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>7.7 where\u548chaving\u7684\u533a\u522b<\/h4>\n<p>\u9762\u8bd5\u5e38\u8003&#xff0c;\u4e5f\u662f\u65b0\u624b\u6700\u5bb9\u6613\u6df7\u7684&#xff0c;\u4e00\u53e5\u8bdd\u8bb2\u660e\u767d&#xff1a; where\u662f\u5206\u7ec4\u524d\u7b5b\u884c&#xff0c;having\u662f\u5206\u7ec4\u540e\u7b5b\u7ec4\u3002<\/p>\n<p>\u6253\u4e2a\u6bd4\u65b9&#xff1a;<\/p>\n<ul>\n<li>\u516c\u53f8\u62db\u5458\u5de5&#xff0c;\u5148\u770b\u5b66\u5386\u7b5b\u6389\u4e00\u6279\u4eba&#xff08;where&#xff0c;\u7b5b\u4e2a\u4f53&#xff09;<\/li>\n<li>\u5269\u4e0b\u7684\u4eba\u6309\u90e8\u95e8\u5206\u7ec4&#xff0c;\u7b97\u6bcf\u4e2a\u90e8\u95e8\u7684\u5e73\u5747\u5de5\u8d44<\/li>\n<li>\u518d\u628a\u5e73\u5747\u5de5\u8d44\u592a\u9ad8\u7684\u90e8\u95e8\u6574\u4e2a\u780d\u6389&#xff08;having&#xff0c;\u7b5b\u6574\u4e2a\u7ec4&#xff09;<\/li>\n<\/ul>\n<table>\n<tr>\u5bf9\u6bd4\u9879wherehaving<\/tr>\n<tbody>\n<tr>\n<td>\u4ec0\u4e48\u65f6\u5019\u6267\u884c<\/td>\n<td>\u5206\u7ec4\u4e4b\u524d<\/td>\n<td>\u5206\u7ec4\u4e4b\u540e<\/td>\n<\/tr>\n<tr>\n<td>\u7b5b\u4ec0\u4e48<\/td>\n<td>\u4e00\u884c\u4e00\u884c\u7684\u6570\u636e<\/td>\n<td>\u5206\u597d\u7684\u6574\u4e2a\u7ec4<\/td>\n<\/tr>\n<tr>\n<td>\u80fd\u7528\u805a\u5408\u51fd\u6570\u5417<\/td>\n<td>\u4e0d\u80fd<\/td>\n<td>\u80fd<\/td>\n<\/tr>\n<tr>\n<td>\u6027\u80fd<\/td>\n<td>\u597d&#xff0c;\u5148\u8fc7\u6ee4\u6570\u636e\u5c11<\/td>\n<td>\u5dee\u4e00\u70b9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6700\u4f73\u5b9e\u8df5&#xff1a;\u80fd\u5728where\u91cc\u8fc7\u6ee4\u7684&#xff0c;\u5c31\u522b\u653e\u5230having\u91cc&#xff0c;\u6027\u80fd\u66f4\u597d\u3002<\/p>\n<hr \/>\n<h3>\u516b\u3001\u5fc5\u61c2\u5e95\u5c42\u903b\u8f91&#xff1a;sql\u6267\u884c\u987a\u5e8f<\/h3>\n<p>\u5f88\u591a\u65b0\u624b\u7591\u60d1&#xff1a;\u4e3a\u4ec0\u4e48where\u91cc\u4e0d\u80fd\u7528\u522b\u540d&#xff1f;\u4e3a\u4ec0\u4e48having\u91cc\u80fd\u7528\u805a\u5408\u51fd\u6570&#xff1f;<\/p>\n<p>\u7b54\u6848\u5f88\u7b80\u5355&#xff1a;sql\u5199\u7684\u987a\u5e8f&#xff0c;\u548c\u5b9e\u9645\u6267\u884c\u7684\u987a\u5e8f&#xff0c;\u5b8c\u5168\u4e0d\u4e00\u6837\u3002<\/p>\n<h4>8.1 \u771f\u5b9e\u6267\u884c\u987a\u5e8f<\/h4>\n<p>from \u2192 where \u2192 group by \u2192 having \u2192 select \u2192 distinct \u2192 order by \u2192 limit<\/p>\n<h4>8.2 \u5927\u767d\u8bdd\u7c7b\u6bd4&#xff1a;\u505a\u83dc\u7684\u987a\u5e8f<\/h4>\n<p>\u4e0d\u7528\u6b7b\u8bb0&#xff0c;\u5c31\u6309\u505a\u83dc\u7684\u903b\u8f91\u60f3&#xff1a;<\/p>\n<li>from&#xff1a;\u5148\u53bb\u83dc\u5e02\u573a\u4e70\u83dc&#xff08;\u627e\u5230\u6570\u636e\u5728\u54ea\u5f20\u8868&#xff09;<\/li>\n<li>where&#xff1a;\u56de\u5bb6\u62e9\u83dc&#xff0c;\u628a\u574f\u7684\u53f6\u5b50\u6254\u6389&#xff08;\u5148\u8fc7\u6ee4\u6389\u6ca1\u7528\u7684\u884c&#xff09;<\/li>\n<li>group by&#xff1a;\u628a\u83dc\u5206\u7c7b&#xff0c;\u9752\u83dc\u653e\u4e00\u5806&#xff0c;\u8089\u653e\u4e00\u5806&#xff08;\u5206\u7ec4&#xff09;<\/li>\n<li>having&#xff1a;\u628a\u574f\u4e86\u7684\u6574\u5806\u83dc\u6254\u6389&#xff08;\u7b5b\u9009\u6574\u4e2a\u7ec4&#xff09;<\/li>\n<li>select&#xff1a;\u5207\u83dc\u88c5\u76d8&#xff0c;\u51b3\u5b9a\u76d8\u5b50\u91cc\u653e\u4ec0\u4e48&#xff08;\u8ba1\u7b97\u5217\u3001\u8d77\u522b\u540d&#xff09;<\/li>\n<li>distinct&#xff1a;\u6311\u6389\u91cd\u590d\u7684\u83dc&#xff08;\u53bb\u91cd&#xff09;<\/li>\n<li>order by&#xff1a;\u76d8\u5b50\u6446\u597d\u770b\u70b9&#xff08;\u6392\u5e8f&#xff09;<\/li>\n<li>limit&#xff1a;\u5ba2\u4eba\u591a&#xff0c;\u5148\u4e0a\u524d3\u76d8&#xff08;\u5206\u9875&#xff09;<\/li>\n<p>\u987a\u7740\u8fd9\u4e2a\u903b\u8f91\u60f3&#xff0c;\u5f88\u591a\u95ee\u9898\u81ea\u7136\u5c31\u61c2\u4e86&#xff1a;<\/p>\n<ul>\n<li>\u4e3a\u4ec0\u4e48where\u4e0d\u80fd\u7528\u522b\u540d&#xff1f;\u62e9\u83dc\u7684\u65f6\u5019&#xff0c;\u83dc\u8fd8\u6ca1\u88c5\u76d8\u5462&#xff0c;\u54ea\u6765\u7684\u83dc\u540d<\/li>\n<li>\u4e3a\u4ec0\u4e48order by\u80fd\u7528\u522b\u540d&#xff1f;\u90fd\u6446\u5b8c\u76d8\u4e86&#xff0c;\u5f53\u7136\u77e5\u9053\u83dc\u540d<\/li>\n<li>\u4e3a\u4ec0\u4e48where\u4e0d\u80fd\u7528\u805a\u5408\u51fd\u6570&#xff1f;\u83dc\u90fd\u6ca1\u5206\u7c7b&#xff0c;\u600e\u4e48\u7b97\u6bcf\u5806\u7684\u5e73\u5747\u91cd\u91cf<\/li>\n<\/ul>\n<h4>8.3 \u61c2\u4e86\u6267\u884c\u987a\u5e8f\u6709\u5565\u7528&#xff1f;<\/h4>\n<li>\u4e0d\u7528\u6b7b\u8bb0\u5404\u79cd\u8bed\u6cd5\u89c4\u5219&#xff0c;\u987a\u7740\u903b\u8f91\u63a8\u5c31\u77e5\u9053\u5bf9\u9519<\/li>\n<li>\u80fd\u81ea\u5df1\u5224\u65adsql\u5199\u5f97\u597d\u4e0d\u597d\u3001\u5feb\u4e0d\u5feb<\/li>\n<li>\u62a5\u9519\u4e86\u80fd\u5feb\u901f\u5b9a\u4f4d\u54ea\u91cc\u51fa\u4e86\u95ee\u9898<\/li>\n<hr \/>\n<h3>\u4e5d\u3001\u65b0\u624b\u907f\u5751\u7ec8\u6781\u6e05\u5355<\/h3>\n<li>\u6c38\u8fdc\u522b\u5199select *&#xff0c;\u9700\u8981\u54ea\u5217\u5199\u54ea\u5217<\/li>\n<li>update\/delete\u4e00\u5b9a\u8981\u52a0where&#xff0c;\u6267\u884c\u524d\u5148\u7528select\u786e\u8ba4<\/li>\n<li>\u5224\u65adnull\u7528is null\/is not null&#xff0c;\u522b\u7528\u7b49\u53f7<\/li>\n<li>\u80fdwhere\u5c31\u522bhaving&#xff0c;\u5148\u8fc7\u6ee4\u518d\u5206\u7ec4\u6027\u80fd\u597d<\/li>\n<li>\u5efa\u8868\u5c3d\u91cf\u7ed9\u9ed8\u8ba4\u503c&#xff0c;\u5c11\u7528null\u5c11\u8e29\u5751<\/li>\n<li>\u6e05\u7a7a\u5927\u8868\u7528truncate&#xff0c;\u6bd4delete\u5feb\u5f88\u591a<\/li>\n<li>limit\u5206\u9875\u4ece0\u5f00\u59cb&#xff0c;\u7b2c\u4e00\u4e2a\u6570\u662f\u504f\u79fb\u91cf\u4e0d\u662f\u9875\u7801<\/li>\n<li>and\u4f18\u5148\u7ea7\u6bd4or\u9ad8&#xff0c;\u591a\u6761\u4ef6\u8bb0\u5f97\u52a0\u62ec\u53f7<\/li>\n<li>\u6240\u6709\u6807\u70b9\u7528\u82f1\u6587\u534a\u89d2&#xff0c;\u4e2d\u6587\u6807\u70b9\u5fc5\u62a5\u9519<\/li>\n<li>\u8868\u540d\u5217\u540d\u907f\u5f00\u5173\u952e\u5b57&#xff0c;\u975e\u8981\u7528\u5c31\u7528\u53cd\u5f15\u53f7\u5305\u8d77\u6765<\/li>\n<li>group by\u540eselect\u5b57\u6bb5\u8981\u4e48\u5206\u7ec4\u8981\u4e48\u805a\u5408&#xff0c;\u522b\u76f4\u63a5\u5199\u975e\u5206\u7ec4\u5b57\u6bb5<\/li>\n<hr \/>\n<h3>\u5341\u3001\u6700\u540e&#xff1a;ai\u65f6\u4ee3\u600e\u4e48\u5b66<\/h3>\n<p>\u73b0\u5728ai\u5199sql\u53c8\u5feb\u53c8\u51c6&#xff0c;\u5f88\u591a\u4eba\u8bf4\u4e0d\u7528\u5b66sql\u4e86\u3002\u5176\u5b9e\u4e0d\u662f\u4e0d\u7528\u5b66&#xff0c;\u662f\u4e0d\u7528\u6b7b\u80cc\u8bed\u6cd5\u4e86&#xff0c;\u4f46\u5e95\u5c42\u903b\u8f91\u5fc5\u987b\u61c2\u3002<\/p>\n<ul>\n<li>\u57fa\u7840\u7684\u5199\u6cd5\u3001\u51fd\u6570\u540d&#xff0c;\u5fd8\u4e86\u53ef\u4ee5\u67e5&#xff0c;\u751a\u81f3\u8ba9ai\u76f4\u63a5\u5199<\/li>\n<li>\u4f46\u6267\u884c\u987a\u5e8f\u3001null\u903b\u8f91\u3001\u5206\u7ec4\u539f\u7406\u3001\u6027\u80fd\u903b\u8f91\u8fd9\u4e9b\u4e1c\u897f&#xff0c;\u5fc5\u987b\u7406\u89e3\u3002\u8fd9\u662f\u4f60\u5224\u65adai\u5199\u5f97\u5bf9\u4e0d\u5bf9\u3001\u6392\u67e5\u7ebf\u4e0a\u95ee\u9898\u7684\u5e95\u6c14\u3002<\/li>\n<\/ul>\n<p>\u628aai\u5f53\u6821\u5bf9\u5de5\u5177&#xff0c;\u4e0d\u662f\u7b54\u6848\u5de5\u5177\u3002\u81ea\u5df1\u5148\u5199&#xff0c;\u518d\u548cai\u7684\u7ed3\u679c\u5bf9\u6bd4&#xff0c;\u60f3\u6e05\u695a\u4e3a\u4ec0\u4e48\u4e0d\u4e00\u6837&#xff0c;\u8fdb\u6b65\u624d\u6700\u5feb\u3002<\/p>\n<p>mysql\u57fa\u672c\u67e5\u8be2\u662f\u540e\u7aef\u5f00\u53d1\u7684\u57fa\u672c\u529f&#xff0c;\u770b\u4f3c\u7b80\u5355&#xff0c;\u7ec6\u8282\u548c\u5751\u975e\u5e38\u591a\u3002\u4f46\u53ea\u8981\u4f60\u987a\u7740\u6570\u636e\u6d41\u52a8\u7684\u903b\u8f91\u53bb\u7406\u89e3&#xff0c;\u4e0d\u7528\u6b7b\u8bb0\u4e5f\u80fd\u7262\u7262\u638c\u63e1\u3002\u591a\u6572\u591a\u7ec3&#xff0c;\u5f88\u5feb\u5c31\u80fd\u719f\u7ec3\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u76ee\u5f55mysql\u57fa\u672c\u67e5\u8be2\u901a\u5173\u624b\u518c&#xff1a;\u4ececrud\u5230\u5206\u7ec4\u7edf\u8ba1&#xff0c;\u65b0\u624b\u907f\u5751\u5168\u653b\u7565\u4e00\u3001\u5148\u641e\u61c2&#xff1a;\u8868\u662f\u4ec0\u4e48&#xff1f;\u4e8c\u3001create&#xff1a;\u5148\u5efa\u4e00\u5f20\u88682.1 \u6700\u7b80\u5355\u7684\u5efa\u8868\u4f8b\u5b502.2 \u5927\u767d\u8bdd\u89e3\u91ca\u6bcf\u4e2a\u8bcd2.3 \u65b0\u624b\u5efa\u8868\u907f\u5751\u4e09\u3001insert&#xff1a;\u5f80\u8868\u91cc\u52a0\u6570\u636e3.1 \u5355\u884c\u5168\u5217\u63d2\u51653.2 \u6307\u5b9a\u5217\u63d2\u51653.3 \u4e00\u6b21\u63d2\u591a\u884c3.4 \u63d2\u5165\u907f\u5751\u56db\u3001select&#xff1a;\u4ece\u8868\u91cc\u67e5\u6570\u636e4.1 \u67e5\u6240\u6709\u52174.2 \u53ea\u67e5\u6307\u5b9a\u52174.3 \u7ed9\u5217\u8d77\u4e2a\u522b\u540d4.4<\/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":[11653,84,114,100],"topic":[],"class_list":["post-113577","post","type-post","status-publish","format-standard","hentry","category-server","tag-11653","tag-android","tag-mysql","tag-100"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MySQL\u6570\u636e\u5e93\uff1a\u57fa\u672c\u67e5\u8be2 - \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\/113577.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL\u6570\u636e\u5e93\uff1a\u57fa\u672c\u67e5\u8be2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u76ee\u5f55mysql\u57fa\u672c\u67e5\u8be2\u901a\u5173\u624b\u518c&#xff1a;\u4ececrud\u5230\u5206\u7ec4\u7edf\u8ba1&#xff0c;\u65b0\u624b\u907f\u5751\u5168\u653b\u7565\u4e00\u3001\u5148\u641e\u61c2&#xff1a;\u8868\u662f\u4ec0\u4e48&#xff1f;\u4e8c\u3001create&#xff1a;\u5148\u5efa\u4e00\u5f20\u88682.1 \u6700\u7b80\u5355\u7684\u5efa\u8868\u4f8b\u5b502.2 \u5927\u767d\u8bdd\u89e3\u91ca\u6bcf\u4e2a\u8bcd2.3 \u65b0\u624b\u5efa\u8868\u907f\u5751\u4e09\u3001insert&#xff1a;\u5f80\u8868\u91cc\u52a0\u6570\u636e3.1 \u5355\u884c\u5168\u5217\u63d2\u51653.2 \u6307\u5b9a\u5217\u63d2\u51653.3 \u4e00\u6b21\u63d2\u591a\u884c3.4 \u63d2\u5165\u907f\u5751\u56db\u3001select&#xff1a;\u4ece\u8868\u91cc\u67e5\u6570\u636e4.1 \u67e5\u6240\u6709\u52174.2 \u53ea\u67e5\u6307\u5b9a\u52174.3 \u7ed9\u5217\u8d77\u4e2a\u522b\u540d4.4\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/113577.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-06T13:57:08+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=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/113577.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/113577.html\",\"name\":\"MySQL\u6570\u636e\u5e93\uff1a\u57fa\u672c\u67e5\u8be2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-06T13:57:08+00:00\",\"dateModified\":\"2026-10-06T13:57:08+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/113577.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/113577.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/113577.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL\u6570\u636e\u5e93\uff1a\u57fa\u672c\u67e5\u8be2\"}]},{\"@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":"MySQL\u6570\u636e\u5e93\uff1a\u57fa\u672c\u67e5\u8be2 - \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\/113577.html","og_locale":"zh_CN","og_type":"article","og_title":"MySQL\u6570\u636e\u5e93\uff1a\u57fa\u672c\u67e5\u8be2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u76ee\u5f55mysql\u57fa\u672c\u67e5\u8be2\u901a\u5173\u624b\u518c&#xff1a;\u4ececrud\u5230\u5206\u7ec4\u7edf\u8ba1&#xff0c;\u65b0\u624b\u907f\u5751\u5168\u653b\u7565\u4e00\u3001\u5148\u641e\u61c2&#xff1a;\u8868\u662f\u4ec0\u4e48&#xff1f;\u4e8c\u3001create&#xff1a;\u5148\u5efa\u4e00\u5f20\u88682.1 \u6700\u7b80\u5355\u7684\u5efa\u8868\u4f8b\u5b502.2 \u5927\u767d\u8bdd\u89e3\u91ca\u6bcf\u4e2a\u8bcd2.3 \u65b0\u624b\u5efa\u8868\u907f\u5751\u4e09\u3001insert&#xff1a;\u5f80\u8868\u91cc\u52a0\u6570\u636e3.1 \u5355\u884c\u5168\u5217\u63d2\u51653.2 \u6307\u5b9a\u5217\u63d2\u51653.3 \u4e00\u6b21\u63d2\u591a\u884c3.4 \u63d2\u5165\u907f\u5751\u56db\u3001select&#xff1a;\u4ece\u8868\u91cc\u67e5\u6570\u636e4.1 \u67e5\u6240\u6709\u52174.2 \u53ea\u67e5\u6307\u5b9a\u52174.3 \u7ed9\u5217\u8d77\u4e2a\u522b\u540d4.4","og_url":"https:\/\/www.wsisp.com\/helps\/113577.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-06T13:57:08+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/113577.html","url":"https:\/\/www.wsisp.com\/helps\/113577.html","name":"MySQL\u6570\u636e\u5e93\uff1a\u57fa\u672c\u67e5\u8be2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-06T13:57:08+00:00","dateModified":"2026-10-06T13:57:08+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/113577.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/113577.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/113577.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"MySQL\u6570\u636e\u5e93\uff1a\u57fa\u672c\u67e5\u8be2"}]},{"@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\/113577","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=113577"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/113577\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=113577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=113577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=113577"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=113577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}