{"id":100516,"date":"2026-09-04T19:04:52","date_gmt":"2026-09-04T11:04:52","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/100516.html"},"modified":"2026-09-04T19:04:52","modified_gmt":"2026-09-04T11:04:52","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e4%b8%8esql%e8%af%ad%e8%a8%80%ef%bc%9a%e4%bb%8e%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%88%b0dql%e6%9f%a5%e8%af%a2%e6%a0%b8%e5%bf%83","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/100516.html","title":{"rendered":"MySQL\u6570\u636e\u5e93\u4e0eSQL\u8bed\u8a00\uff1a\u4ece\u6570\u636e\u7c7b\u578b\u5230DQL\u67e5\u8be2\u6838\u5fc3"},"content":{"rendered":"<\/p>\n<h2>\u7b2c\u4e00\u90e8\u5206&#xff1a;\u6570\u636e\u5e93\u57fa\u7840<\/h2>\n<h4>1.1 \u4ec0\u4e48\u662f\u6570\u636e\u5e93<\/h4>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;\u6570\u636e\u5e93\u662f\u957f\u671f\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u5185\u7684\u3001\u6709\u7ec4\u7ec7\u7684\u3001\u53ef\u5171\u4eab\u7684\u6570\u636e\u96c6\u5408&#xff0c;\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u6587\u4ef6\u7cfb\u7edf\u3002\u548cExcel\u4e0d\u540c&#xff0c;Excel\u968f\u4fbf\u585e\u6570\u636e\u6ca1\u683c\u5f0f\u7ea6\u675f&#xff0c;\u800c\u6570\u636e\u5e93\u5fc5\u987b\u6309\u63d0\u524d\u8bbe\u597d\u7684\u7279\u5b9a\u683c\u5f0f\u5b58\u6570\u636e\u3002<\/p>\n<p>\u6570\u636e\u5e93 vs Excel&#xff1a;<\/p>\n<table>\n<tr>\u5bf9\u6bd4Excel\u6570\u636e\u5e93<\/tr>\n<tbody>\n<tr>\n<td>\u6570\u636e\u7ea6\u675f<\/td>\n<td>\u65e0\u683c\u5f0f\u9650\u5236<\/td>\n<td>\u5fc5\u987b\u7b26\u5408\u9884\u8bbe\u8868\u7ed3\u6784<\/td>\n<\/tr>\n<tr>\n<td>\u6570\u636e\u91cf<\/td>\n<td>\u9002\u5408\u5c0f\u6570\u636e<\/td>\n<td>\u652f\u6301\u6d77\u91cf\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td>\u5e76\u53d1\u8bbf\u95ee<\/td>\n<td>\u5f31<\/td>\n<td>\u5f3a<\/td>\n<\/tr>\n<tr>\n<td>\u6570\u636e\u89c4\u8303<\/td>\n<td>\u4e0d\u4e25\u683c<\/td>\n<td>\u4e25\u683c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>1.2 \u6570\u636e\u5e93\u5206\u7c7b<\/h4>\n<table>\n<tr>\u7c7b\u578b\u8bf4\u660e\u4ee3\u8868\u4ea7\u54c1\u662f\u5426\u652f\u6301SQL<\/tr>\n<tbody>\n<tr>\n<td>\u5173\u7cfb\u578b\u6570\u636e\u5e93<\/td>\n<td>\u7528\u4e8c\u7ef4\u8868\u5b58\u50a8\u6570\u636e<\/td>\n<td>MySQL\u3001SQL Server\u3001DB2\u3001Oracle<\/td>\n<td>\u2705 \u652f\u6301<\/td>\n<\/tr>\n<tr>\n<td>\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93&#xff08;NoSQL&#xff09;<\/td>\n<td>\u975e\u4e8c\u7ef4\u8868\u5b58\u50a8&#xff08;\u952e\u503c\u5bf9\u3001\u6587\u6863\u7b49&#xff09;<\/td>\n<td>Redis\u3001MongoDB<\/td>\n<td>\u274c \u4e0d\u652f\u6301<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;\u5173\u7cfb\u578b\u6570\u636e\u5e93\u90fd\u652f\u6301SQL\u8bed\u8a00\u64cd\u4f5c&#xff1b;\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93\u6682\u65f6\u4e0d\u652f\u6301SQL\u3002\u4e24\u8005\u9002\u7528\u573a\u666f\u4e0d\u540c&#xff0c;\u590d\u6742\u9879\u76ee\u5e38\u9700\u642d\u914d\u4f7f\u7528\u3002<\/p>\n<h4>1.3 SQL\u8bed\u8a00\u6982\u8ff0<\/h4>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;SQL&#xff08;Structured Query Language&#xff0c;\u7ed3\u6784\u5316\u67e5\u8be2\u8bed\u8a00&#xff09;\u662f\u7a0b\u5e8f\u4e0e\u6570\u636e\u5e93\u6c9f\u901a\u7684\u552f\u4e00\u8bed\u8a00&#xff0c;\u6240\u6709\u5173\u7cfb\u578b\u6570\u636e\u5e93\u90fd\u80fd\u7528SQL\u64cd\u4f5c&#xff0c;\u5404\u5e93\u4ec5\u6709\u7ec6\u5fae\u5dee\u522b\u3002<\/p>\n<p>SQL\u8bed\u8a00\u5206\u7c7b&#xff1a;<\/p>\n<table>\n<tr>\u5206\u7c7b\u5168\u79f0\u64cd\u4f5c\u5bf9\u8c61\u5e38\u7528\u5173\u952e\u5b57<\/tr>\n<tbody>\n<tr>\n<td>DDL<\/td>\n<td>\u6570\u636e\u5b9a\u4e49\u8bed\u8a00<\/td>\n<td>\u6570\u636e\u5e93\u3001\u8868\u7ed3\u6784<\/td>\n<td>CREATE\u3001ALTER\u3001DROP\u3001SHOW\u3001USE<\/td>\n<\/tr>\n<tr>\n<td>DML<\/td>\n<td>\u6570\u636e\u64cd\u4f5c\u8bed\u8a00<\/td>\n<td>\u8868\u4e2d\u6570\u636e<\/td>\n<td>INSERT\u3001UPDATE\u3001DELETE<\/td>\n<\/tr>\n<tr>\n<td>DQL<\/td>\n<td>\u6570\u636e\u67e5\u8be2\u8bed\u8a00<\/td>\n<td>\u8868\u4e2d\u6570\u636e&#xff08;\u67e5\u8be2&#xff09;<\/td>\n<td>SELECT<\/td>\n<\/tr>\n<tr>\n<td>DCL<\/td>\n<td>\u6570\u636e\u63a7\u5236\u8bed\u8a00<\/td>\n<td>\u7528\u6237\u6743\u9650<\/td>\n<td>CREATE USER\u3001GRANT\u3001REVOKE<\/td>\n<\/tr>\n<tr>\n<td>TCL<\/td>\n<td>\u4e8b\u52a1\u63a7\u5236\u8bed\u8a00<\/td>\n<td>\u4e8b\u52a1<\/td>\n<td>BEGIN\u3001COMMIT\u3001ROLLBACK<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u7b2c\u4e8c\u90e8\u5206&#xff1a;MySQL\u6570\u636e\u7c7b\u578b<\/h3>\n<h4>2.1 \u6570\u503c\u7c7b\u578b<\/h4>\n<table>\n<tr>\u7c7b\u578b\u5b57\u8282\u6570\u53d6\u503c\u8303\u56f4\u7528\u9014<\/tr>\n<tbody>\n<tr>\n<td>tinyint<\/td>\n<td>1<\/td>\n<td>-128 ~ 127<\/td>\n<td>\u72b6\u6001\u503c&#xff08;0\/1\/2&#xff09;\u3001\u6027\u522b\u5f00\u5173<\/td>\n<\/tr>\n<tr>\n<td>smallint<\/td>\n<td>2<\/td>\n<td>-32768 ~ 32767<\/td>\n<td>\u8f83\u5c0f\u6574\u6570<\/td>\n<\/tr>\n<tr>\n<td>mediumint<\/td>\n<td>3<\/td>\n<td>-8388608 ~ 8388607<\/td>\n<td>\u4e2d\u7b49\u6574\u6570<\/td>\n<\/tr>\n<tr>\n<td>int<\/td>\n<td>4<\/td>\n<td>-21\u4ebf ~ 21\u4ebf<\/td>\n<td>\u6700\u5e38\u7528\u6574\u6570<\/td>\n<\/tr>\n<tr>\n<td>bigint<\/td>\n<td>8<\/td>\n<td>\u8d85\u5927\u8303\u56f4<\/td>\n<td>\u8ba2\u5355\u53f7\u3001\u5927\u6570\u636e\u91cf\u4e3b\u952e<\/td>\n<\/tr>\n<tr>\n<td>float<\/td>\n<td>4<\/td>\n<td>\u5355\u7cbe\u5ea6\u5c0f\u6570<\/td>\n<td>\u6709\u7cbe\u5ea6\u4e22\u5931<\/td>\n<\/tr>\n<tr>\n<td>double<\/td>\n<td>8<\/td>\n<td>\u53cc\u7cbe\u5ea6\u5c0f\u6570<\/td>\n<td>\u6709\u7cbe\u5ea6\u4e22\u5931<\/td>\n<\/tr>\n<tr>\n<td>decimal<\/td>\n<td>\u52a8\u6001<\/td>\n<td>\u7cbe\u786e\u5c0f\u6570<\/td>\n<td>\u91d1\u989d\u3001\u4ef7\u683c&#xff08;\u65e0\u7cbe\u5ea6\u4e22\u5931&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7c7b\u578b\u9009\u62e9\u8981\u70b9&#xff1a;<\/p>\n<p>&#8212; \u72b6\u6001\u503c \u2192 tinyint&#xff08;\u7701\u7a7a\u95f4&#xff09;<br \/>\nsex TINYINT DEFAULT 0  &#8212; 0\u7537 1\u5973<\/p>\n<p>&#8212; \u666e\u901a\u6574\u6570 \u2192 int<br \/>\nage INT<\/p>\n<p>&#8212; \u8ba2\u5355\u53f7 \u2192 bigint<br \/>\norder_id BIGINT<\/p>\n<p>&#8212; \u91d1\u989d \u2192 decimal&#xff08;\u907f\u514d\u7cbe\u5ea6\u4e22\u5931&#xff09;<br \/>\nprice DECIMAL(10,2)  &#8212; \u603b\u957f\u5ea610\u4f4d&#xff0c;\u5c0f\u65702\u4f4d<\/p>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;int\u6700\u5927\u503c\u8fbe\u4e0d\u523011\u4f4d&#xff0c;\u624b\u673a\u53f7\u4e0d\u80fd\u7528int\u5b58\u3002\u6d89\u53ca\u91d1\u94b1\u3001\u4ef7\u683c\u7b49\u91d1\u989d\u5b57\u6bb5&#xff0c;\u4e0d\u8981\u7528float\/double&#xff0c;\u5fc5\u987b\u7528decimal&#xff0c;\u907f\u514d\u7cbe\u5ea6\u4e22\u5931\u3002\u624b\u673a\u53f7\u53ef\u80fd\u542b\u533a\u53f7\u4e14\u9996\u4f4d\u4e3a0&#xff0c;\u5efa\u8bae\u7528\u5b57\u7b26\u4e32\u5b58\u3002<\/p>\n<h4>2.2 \u5b57\u7b26\u4e32\u7c7b\u578b<\/h4>\n<table>\n<tr>\u7c7b\u578b\u7279\u70b9\u6700\u5927\u957f\u5ea6\u9002\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>char<\/td>\n<td>\u56fa\u5b9a\u957f\u5ea6&#xff0c;\u4e0d\u8db3\u8865\u7a7a\u683c<\/td>\n<td>255<\/td>\n<td>\u624b\u673a\u53f7(11\u4f4d)\u3001\u8eab\u4efd\u8bc1\u53f7\u3001\u9a8c\u8bc1\u7801<\/td>\n<\/tr>\n<tr>\n<td>varchar<\/td>\n<td>\u53ef\u53d8\u957f\u5ea6&#xff0c;\u5b58\u5b9e\u9645\u5b57\u7b26<\/td>\n<td>65535<\/td>\n<td>\u59d3\u540d\u3001\u5730\u5740\u3001\u6807\u9898&#xff08;\u957f\u5ea6\u4e0d\u4e00&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>text<\/td>\n<td>\u53ef\u53d8\u5927\u6587\u672c&#xff0c;\u65e0\u957f\u5ea6\u9650\u5236<\/td>\n<td>\u65e0\u9650\u5236<\/td>\n<td>\u6587\u7ae0\u5185\u5bb9\u3001\u5bcc\u6587\u672c\u5185\u5bb9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&#8212; \u56fa\u5b9a\u957f\u5ea6 \u2192 char<br \/>\nphone CHAR(11)<\/p>\n<p>&#8212; \u957f\u5ea6\u4e0d\u4e00\u4f46\u6709\u9650 \u2192 varchar<br \/>\nname VARCHAR(50)<br \/>\ntitle VARCHAR(255)  &#8212; \u4e60\u60ef\u8bbe255<\/p>\n<p>&#8212; \u5185\u5bb9\u4e0d\u53ef\u9884\u77e5 \u2192 text<br \/>\ncontent TEXT<\/p>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;char\u50cf\u5b9a\u957f\u683c\u5b50&#xff0c;\u4e0d\u7ba1\u653e\u6ca1\u653e\u6ee1\u90fd\u5360\u90a3\u4e48\u5927\u5730\u65b9\u3002varchar\u53ea\u5b58\u5b9e\u9645\u6570\u636e&#xff0c;\u4f46\u8d85255\u540e\u6bcf\u5b58\u4e00\u4e2a\u503c\u9700\u591a\u53602\u5b57\u8282\u3002text\u6765\u591a\u5c11\u5b58\u591a\u5c11&#xff0c;\u4e13\u6cbb&#034;\u65e0\u9650\u957f&#034;\u5185\u5bb9\u3002<\/p>\n<h4>2.3 \u65e5\u671f\u65f6\u95f4\u7c7b\u578b<\/h4>\n<table>\n<tr>\u7c7b\u578b\u683c\u5f0f\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>date<\/td>\n<td>yyyy-MM-dd<\/td>\n<td>\u4ec5\u65e5\u671f&#xff08;\u5e74\u6708\u65e5&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>time<\/td>\n<td>HH:mm:ss<\/td>\n<td>\u4ec5\u65f6\u95f4&#xff08;\u65f6\u5206\u79d2&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>datetime<\/td>\n<td>yyyy-MM-dd HH:mm:ss<\/td>\n<td>\u65e5\u671f&#043;\u65f6\u95f4<\/td>\n<\/tr>\n<tr>\n<td>year<\/td>\n<td>yyyy<\/td>\n<td>\u4ec5\u5e74\u4efd<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>birth_date DATE<br \/>\ncreated_at DATETIME<\/p>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;date\u53ea\u5b58\u5e74\u6708\u65e5&#xff0c;datetime\u5305\u542b\u65f6\u5206\u79d2&#xff0c;\u9009\u54ea\u4e2a\u770b\u662f\u5426\u9700\u8981\u7cbe\u786e\u5230\u79d2\u3002<\/p>\n<h3>\u7b2c\u4e09\u90e8\u5206&#xff1a;\u6570\u636e\u5e93\u7ea6\u675f<\/h3>\n<h4>3.1 \u7ea6\u675f\u6982\u8ff0<\/h4>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;\u7ea6\u675f\u662f\u4e3a\u4e86\u786e\u4fdd\u6570\u636e\u7684\u51c6\u786e\u6027\u4e0e\u5b8c\u6574\u6027&#xff0c;\u9650\u5236\u6570\u636e\u5b58\u53d6\u89c4\u5219&#xff0c;\u4e0d\u662f\u4ec0\u4e48\u6570\u636e\u90fd\u80fd\u968f\u4fbf\u5199\u3002<\/p>\n<h4>3.2 \u5e38\u7528\u7ea6\u675f<\/h4>\n<table>\n<tr>\u7ea6\u675f\u7c7b\u578b\u8bf4\u660e\u4f5c\u7528\u8303\u56f4<\/tr>\n<tbody>\n<tr>\n<td>\u4e3b\u952e\u7ea6\u675f<\/td>\n<td>\u975e\u7a7a&#043;\u552f\u4e00&#xff0c;\u6807\u8bc6\u6574\u884c<\/td>\n<td>\u5217\u7ea7\/\u8868\u7ea7<\/td>\n<\/tr>\n<tr>\n<td>\u81ea\u589e\u7ea6\u675f<\/td>\n<td>\u6570\u503c\u81ea\u52a8&#043;1<\/td>\n<td>\u5217\u7ea7<\/td>\n<\/tr>\n<tr>\n<td>\u975e\u7a7a\u7ea6\u675f<\/td>\n<td>\u5b57\u6bb5\u5fc5\u987b\u6709\u503c<\/td>\n<td>\u5217\u7ea7<\/td>\n<\/tr>\n<tr>\n<td>\u9ed8\u8ba4\u503c\u7ea6\u675f<\/td>\n<td>\u63d2\u5165\u4e0d\u586b\u65f6\u81ea\u52a8\u586b\u5145<\/td>\n<td>\u5217\u7ea7<\/td>\n<\/tr>\n<tr>\n<td>\u552f\u4e00\u7ea6\u675f<\/td>\n<td>\u5b57\u6bb5\u503c\u4e0d\u80fd\u91cd\u590d&#xff08;\u53ef\u4e3a\u7a7a&#xff09;<\/td>\n<td>\u5217\u7ea7\/\u8868\u7ea7<\/td>\n<\/tr>\n<tr>\n<td>\u5916\u952e\u7ea6\u675f<\/td>\n<td>\u5f15\u7528\u5176\u4ed6\u8868\u4e3b\u952e<\/td>\n<td>\u8868\u7ea7<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;\u4e3b\u952e\u4e00\u5f20\u8868\u53ea\u80fd\u6709\u4e00\u4e2a&#xff0c;\u4f46\u53ef\u7531\u591a\u4e2a\u5b57\u6bb5\u7ec4\u6210&#xff08;\u8054\u5408\u4e3b\u952e&#xff09;\u3002\u4e3b\u952e\u9ed8\u8ba4\u975e\u7a7a\u4e14\u552f\u4e00&#xff0c;\u8bbe\u4e3b\u952e\u540e\u4e0d\u5fc5\u91cd\u590d\u5199NOT NULL\u3002\u4e3b\u952e\u4e4b\u5916\u5176\u4ed6\u5b57\u6bb5\u90fd\u53ef\u91cd\u590d&#xff0c;\u53ea\u8981\u4e3b\u952e\u4e0d\u540c\u5c31\u662f\u4e0d\u540c\u6570\u636e\u3002<\/p>\n<h4>3.3 \u5217\u7ea7\u7ea6\u675f vs \u8868\u7ea7\u7ea6\u675f<\/h4>\n<table>\n<tr>\u7ea6\u675f\u7c7b\u578b\u4f5c\u7528\u8303\u56f4\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>\u5217\u7ea7\u7ea6\u675f<\/td>\n<td>\u9488\u5bf9\u5f53\u524d\u5355\u5217<\/td>\n<td>NOT NULL\u3001DEFAULT\u3001UNIQUE\u3001PRIMARY KEY<\/td>\n<\/tr>\n<tr>\n<td>\u8868\u7ea7\u7ea6\u675f<\/td>\n<td>\u9488\u5bf9\u6574\u5f20\u8868<\/td>\n<td>\u8054\u5408\u4e3b\u952e\u3001\u591a\u5b57\u6bb5\u552f\u4e00\u7ea6\u675f\u3001\u5916\u952e\u7ea6\u675f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>CREATE TABLE demo (<br \/>\n    &#8212; \u5217\u7ea7\u7ea6\u675f<br \/>\n    id INT PRIMARY KEY AUTO_INCREMENT COMMENT &#039;\u4e3b\u952e&#039;,<br \/>\n    name VARCHAR(20) NOT NULL COMMENT &#039;\u59d3\u540d&#039;,<br \/>\n    age INT DEFAULT 18 COMMENT &#039;\u5e74\u9f84&#039;,<br \/>\n    &#8212; \u8868\u7ea7\u7ea6\u675f&#xff08;\u5199\u5728\u6700\u540e&#xff09;<br \/>\n    FOREIGN KEY (cid) REFERENCES class(id)<br \/>\n);<\/p>\n<h4>3.4 \u5916\u952e\u7ea6\u675f<\/h4>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;\u5916\u952e\u662f\u5b57\u6bb5\u503c\u53d6\u81ea\u53e6\u4e00\u8868\u4e3b\u952e\u7684\u5b57\u6bb5&#xff0c;\u5982student\u8868\u7684cid\u5bf9\u5e94class\u8868\u7684id\u3002\u4f46\u5b9e\u9645\u5f00\u53d1\u4e2d\u5f88\u5c11\u8bbe\u5e93\u7ea7\u5916\u952e&#xff0c;\u56e0\u4e3a\u5220\u9664\u3001\u6dfb\u52a0\u9650\u5236\u9ebb\u70e6\u3002\u6539\u7528\u4e1a\u52a1\u4ee3\u7801\u63a7\u5236&#xff1a;\u6dfb\u52a0\u524d\u67e5class\u8868&#xff0c;\u975e1\u30012\u7981\u6b62\u5199\u5165\u3002<\/p>\n<h3>\u7b2c\u56db\u90e8\u5206&#xff1a;DDL \u2014 \u6570\u636e\u5b9a\u4e49\u8bed\u8a00<\/h3>\n<h4>4.1 \u6570\u636e\u5e93\u64cd\u4f5c<\/h4>\n<p>&#8212; \u521b\u5efa\u6570\u636e\u5e93&#xff08;\u82e5\u4e0d\u5b58\u5728&#xff09;<br \/>\nCREATE DATABASE IF NOT EXISTS test DEFAULT CHARSET utf8mb4;<\/p>\n<p>&#8212; \u67e5\u770b\u6240\u6709\u6570\u636e\u5e93<br \/>\nSHOW DATABASES;<\/p>\n<p>&#8212; \u5207\u6362\u6570\u636e\u5e93<br \/>\nUSE qcby07;<\/p>\n<p>&#8212; \u5220\u9664\u6570\u636e\u5e93&#xff08;\u26a0\ufe0f\u614e\u7528&#xff09;<br \/>\nDROP DATABASE IF EXISTS test;<\/p>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;\u4e0d\u5efa\u8bae\u7528DROP\u5220\u5e93&#xff0c;\u53ef\u80fd\u76f4\u63a5\u5220\u6389\u7cfb\u7edf\u6587\u4ef6&#xff0c;\u65b0\u624b\u6613\u8bef\u5220\u3002<\/p>\n<h4>4.2 \u8868\u64cd\u4f5c<\/h4>\n<p>&#8212; \u5efa\u8868\u8bed\u6cd5<br \/>\nCREATE TABLE \u8868\u540d(<br \/>\n    \u5b57\u6bb5\u540d \u6570\u636e\u7c7b\u578b \u5217\u7ea7\u5b8c\u6574\u6027\u7ea6\u675f\u6761\u4ef6,<br \/>\n    \u5b57\u6bb5\u540d \u6570\u636e\u7c7b\u578b \u5217\u7ea7\u5b8c\u6574\u6027\u7ea6\u675f\u6761\u4ef6,<br \/>\n    \u8868\u7ea7\u7ea6\u675f\u6761\u4ef6<br \/>\n);<\/p>\n<p>&#8212; \u5efa\u8868\u793a\u4f8b<br \/>\nCREATE TABLE demo(<br \/>\n    id INT(11) PRIMARY KEY AUTO_INCREMENT COMMENT &#039;demoid&#039;,<br \/>\n    name VARCHAR(20) NOT NULL COMMENT &#039;demo\u59d3\u540d&#039;,<br \/>\n    age INT(11) DEFAULT 18 COMMENT &#039;\u5e74\u9f84&#039;<br \/>\n);<\/p>\n<p>&#8212; \u67e5\u770b\u8868\u7ed3\u6784<br \/>\nDESC demo;<\/p>\n<p>&#8212; \u4fee\u6539\u8868\u7ed3\u6784&#xff08;\u6dfb\u52a0\u5b57\u6bb5&#xff09;<br \/>\nALTER TABLE demo ADD sex VARCHAR(20);<\/p>\n<p>&#8212; \u4fee\u6539\u8868\u7ed3\u6784&#xff08;\u4fee\u6539\u5b57\u6bb5\u7c7b\u578b&#xff09;<br \/>\nALTER TABLE demo MODIFY sex INT(5);<\/p>\n<p>&#8212; \u4fee\u6539\u8868\u7ed3\u6784&#xff08;\u5220\u9664\u5b57\u6bb5&#xff09;<br \/>\nALTER TABLE demo DROP sex;<\/p>\n<p>&#8212; \u5220\u9664\u8868&#xff08;\u82e5\u5b58\u5728&#xff09;<br \/>\nDROP TABLE IF EXISTS demo;<\/p>\n<h4>4.3 ALTER\u8bed\u53e5\u7684\u56db\u79cd\u64cd\u4f5c<\/h4>\n<table>\n<tr>\u64cd\u4f5c\u5173\u952e\u5b57\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u6dfb\u52a0\u5b57\u6bb5<\/td>\n<td>ADD<\/td>\n<td>\u65b0\u589e\u5b57\u6bb5<\/td>\n<\/tr>\n<tr>\n<td>\u4fee\u6539\u5b57\u6bb5\u7c7b\u578b<\/td>\n<td>MODIFY<\/td>\n<td>\u6539\u5b57\u6bb5\u7c7b\u578b<\/td>\n<\/tr>\n<tr>\n<td>\u4fee\u6539\u5b57\u6bb5\u540d<\/td>\n<td>CHANGE<\/td>\n<td>\u6539\u540d&#043;\u7c7b\u578b<\/td>\n<\/tr>\n<tr>\n<td>\u5220\u9664\u5b57\u6bb5<\/td>\n<td>DROP<\/td>\n<td>\u5220\u9664\u5b57\u6bb5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>4.4 \u53cd\u5f15\u53f7\u7684\u4f7f\u7528<\/h4>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;\u8868\u540d\u6216\u5b57\u6bb5\u540d\u82e5\u4e0eSQL\u5173\u952e\u5b57\u91cd\u540d&#xff0c;\u76f4\u63a5\u5199\u4f1a\u62a5\u9519\u3002\u7528\u952e\u76d8\u5de6\u4e0a\u89d2\u7684**\u53cd\u5f15\u53f7&#xff08;&#096;&#xff09;**\u505a\u8f6c\u4e49&#xff0c;\u649e\u540d\u4e5f\u80fd\u6b63\u5e38\u6267\u884c\u3002<\/p>\n<p>&#8212; \u5982\u679c\u8868\u540d\u53ebselect&#xff0c;\u5fc5\u987b\u52a0\u53cd\u5f15\u53f7<br \/>\nSELECT * FROM &#096;select&#096;;<\/p>\n<h3>\u7b2c\u4e94\u90e8\u5206&#xff1a;DML \u2014 \u6570\u636e\u64cd\u4f5c\u8bed\u8a00<\/h3>\n<h4>5.1 \u63d2\u5165\u6570\u636e&#xff08;INSERT&#xff09;<\/h4>\n<p>&#8212; \u57fa\u672c\u63d2\u5165&#xff08;id\u81ea\u52a8\u9012\u589e&#xff09;<br \/>\nINSERT INTO student(name, age, sex) VALUES (&#039;\u68a8\u82b1&#039;, 25, &#039;\u5973&#039;);<\/p>\n<p>&#8212; \u63d2\u5165\u591a\u6761<br \/>\nINSERT INTO student(name, age) VALUES (&#039;\u5f20\u4e09&#039;, 20), (&#039;\u674e\u56db&#039;, 21);<\/p>\n<h4>5.2 \u4fee\u6539\u6570\u636e&#xff08;UPDATE&#xff09;<\/h4>\n<p>&#8212; \u26a0\ufe0f \u5fc5\u987b\u52a0WHERE\u6761\u4ef6<br \/>\nUPDATE student SET name&#061;&#039;lili12&#039;, age&#061;30 WHERE id&#061;4;<\/p>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;UPDATE\u5fc5\u987b\u52a0WHERE\u6761\u4ef6&#xff0c;\u5426\u5219\u6574\u5f20\u8868\u6240\u6709\u8bb0\u5f55\u90fd\u4f1a\u88ab\u4fee\u6539&#xff01;<\/p>\n<h4>5.3 \u5220\u9664\u6570\u636e&#xff08;DELETE&#xff09;<\/h4>\n<p>&#8212; \u26a0\ufe0f \u5fc5\u987b\u52a0WHERE\u6761\u4ef6<br \/>\nDELETE FROM student WHERE id&#061;7;<\/p>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;DELETE\u5fc5\u987b\u52a0WHERE\u6761\u4ef6&#xff0c;\u5426\u5219\u6574\u5f20\u8868\u6570\u636e\u5168\u90e8\u5220\u9664&#xff01;<\/p>\n<h3>\u7b2c\u516d\u90e8\u5206&#xff1a;DQL \u2014 \u6570\u636e\u67e5\u8be2\u8bed\u8a00&#xff08;\u6838\u5fc3&#xff09;<\/h3>\n<h4>6.1 \u57fa\u7840\u67e5\u8be2<\/h4>\n<p>&#8212; \u67e5\u8be2\u5168\u90e8\u5b57\u6bb5&#xff08;*&#xff09;<br \/>\nSELECT * FROM student;<\/p>\n<p>&#8212; \u67e5\u8be2\u6307\u5b9a\u5b57\u6bb5&#xff08;\u591a\u5b57\u6bb5\u7528\u9017\u53f7\u9694\u5f00&#xff09;<br \/>\nSELECT id, name, age, sex FROM student;<\/p>\n<p>&#8212; \u53bb\u91cd\u67e5\u8be2<br \/>\nSELECT DISTINCT age FROM student;<\/p>\n<p>&#8212; \u522b\u540d&#xff1a;AS\u53ef\u7701\u7565<br \/>\nSELECT age AS \u5e74\u9f84 FROM student;<br \/>\nSELECT age \u5e74\u9f84 FROM student;  &#8212; \u7701\u7565AS<\/p>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;\u67e5\u8be2\u662f\u884c\u7ea7\u904d\u5386&#xff0c;\u6bcf\u884c\u53d6\u5b57\u6bb5\u503c\u3002*\u4ee3\u8868\u5168\u5b57\u6bb5&#xff0c;\u591a\u4e2a\u5b57\u6bb5\u7528\u9017\u53f7\u800c\u975e\u7a7a\u683c\u5206\u9694\u3002AS\u53ef\u7701\u7565&#xff0c;\u7528\u7a7a\u683c\u9694\u5f00\u5373\u53ef\u3002<\/p>\n<h4>6.2 WHERE\u6761\u4ef6\u7b5b\u9009<\/h4>\n<p>\u6bd4\u8f83\u8fd0\u7b97\u7b26&#xff1a;<\/p>\n<p>&#8212; \u5927\u4e8e \u5c0f\u4e8e \u7b49\u4e8e<br \/>\nSELECT * FROM student WHERE age &gt; 20;<br \/>\nSELECT * FROM student WHERE age &gt;&#061; 18;<br \/>\nSELECT * FROM student WHERE age &#061; 24;<\/p>\n<p>&#8212; \u4e0d\u7b49\u4e8e&#xff08;\u4e24\u79cd\u5199\u6cd5&#xff09;<br \/>\nSELECT * FROM student WHERE age !&#061; 24;<br \/>\nSELECT * FROM student WHERE age &lt;&gt; 24;  &#8212; \u7b49\u4ef7<\/p>\n<p>IN \u4e0e BETWEEN&#xff1a;<\/p>\n<p>&#8212; IN&#xff1a;\u503c\u5728\u6307\u5b9a\u96c6\u5408\u4e2d<br \/>\nSELECT * FROM student WHERE age IN (18, 31, 28);<\/p>\n<p>&#8212; BETWEEN AND&#xff1a;\u95ed\u533a\u95f4&#xff08;\u542b\u4e24\u7aef&#xff09;<br \/>\nSELECT * FROM student WHERE age BETWEEN 18 AND 28;<\/p>\n<p>&#8212; \u5f00\u533a\u95f4&#xff08;\u4e0d\u542b18\u548c28&#xff09;<br \/>\nSELECT * FROM student WHERE age &gt; 18 AND age &lt; 28;<\/p>\n<p>\u903b\u8f91\u8fd0\u7b97\u7b26&#xff1a;<\/p>\n<p>&#8212; AND&#xff1a;\u5fc5\u987b\u540c\u65f6\u6ee1\u8db3<br \/>\nSELECT * FROM student WHERE age &gt; 18 AND age &lt;&#061; 28 AND name &#061; &#039;\u674e\u56db&#039;;<\/p>\n<p>&#8212; OR&#xff1a;\u6ee1\u8db3\u4efb\u4e00\u5373\u53ef<br \/>\nSELECT * FROM student WHERE age &gt; 30 OR name &#061; &#039;\u674e\u56db&#039;;<\/p>\n<p>&#8212; NOT IN&#xff1a;\u4e0d\u5728\u96c6\u5408\u4e2d<br \/>\nSELECT * FROM student WHERE age NOT IN (18, 31, 28);<\/p>\n<p>&#8212; IS NULL \/ IS NOT NULL&#xff1a;\u5224\u7a7a<br \/>\nSELECT * FROM student WHERE age IS NOT NULL;<\/p>\n<p>\u6a21\u7cca\u67e5\u627e&#xff08;LIKE&#xff09;&#xff1a;<\/p>\n<p>&#8212; _&#xff1a;\u6070\u597d\u4e00\u4f4d\u5b57\u7b26<br \/>\nSELECT * FROM student WHERE name LIKE &#039;_a_&#039;;  &#8212; \u540d\u5b57\u4e3a3\u4f4d&#xff0c;\u4e2d\u95f4\u662fa<\/p>\n<p>&#8212; %&#xff1a;\u4efb\u610f\u4f4d\u5b57\u7b26&#xff08;\u542b0\u4f4d&#xff09;<br \/>\nSELECT * FROM student WHERE name LIKE &#039;%a%&#039;;  &#8212; \u5305\u542ba\u5373\u53ef<br \/>\nSELECT * FROM student WHERE name LIKE &#039;a%&#039;;   &#8212; \u4ee5a\u5f00\u5934<br \/>\nSELECT * FROM student WHERE name LIKE &#039;%a&#039;;   &#8212; \u4ee5a\u7ed3\u5c3e<\/p>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;LIKE\u4e0d\u52a0\u5360\u4f4d\u7b26\u65f6\u548c\u7b49\u53f7\u6ca1\u533a\u522b\u3002%\u53ef\u5339\u914d\u4efb\u610f\u957f\u5ea6&#xff0c;_\u53ea\u5360\u4e00\u4f4d\u4e0d\u80fd\u7a7a\u3002<\/p>\n<h4>6.3 ORDER BY \u2014 \u6392\u5e8f<\/h4>\n<p>&#8212; \u5347\u5e8f&#xff08;ASC\u53ef\u7701\u7565&#xff0c;\u9ed8\u8ba4&#xff09;<br \/>\nSELECT * FROM student ORDER BY age ASC;<br \/>\nSELECT * FROM student ORDER BY age;  &#8212; \u9ed8\u8ba4\u5347\u5e8f<\/p>\n<p>&#8212; \u964d\u5e8f<br \/>\nSELECT * FROM student ORDER BY age DESC;<\/p>\n<p>&#8212; \u6309\u65e5\u671f\u5012\u5e8f&#xff08;\u6700\u65b0\u5728\u524d&#xff09;<br \/>\nSELECT * FROM student ORDER BY birth DESC;<\/p>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;ASC\u8868\u793a\u5347\u5e8f&#xff0c;\u53ef\u7701\u7565&#xff1b;DESC\u8868\u793a\u964d\u5e8f&#xff0c;\u4e0d\u80fd\u7701\u3002\u6587\u672c\u5b57\u6bb5\u6392\u5e8f\u53d7\u5b57\u7b26\u7f16\u7801\u5f71\u54cd\u3002<\/p>\n<h4>6.4 LIMIT \u2014 \u5206\u9875\u67e5\u8be2<\/h4>\n<p>&#8212; \u8bed\u6cd51&#xff1a;LIMIT \u8d77\u59cb\u7d22\u5f15, \u67e5\u8be2\u6761\u6570<br \/>\nSELECT * FROM student LIMIT 0, 2;  &#8212; \u7b2c1\u9875&#xff08;\u7d22\u5f15\u4ece0\u5f00\u59cb&#xff09;<br \/>\nSELECT * FROM student LIMIT 2, 2;  &#8212; \u7b2c2\u9875<br \/>\nSELECT * FROM student LIMIT 4, 2;  &#8212; \u7b2c3\u9875<\/p>\n<p>&#8212; \u8bed\u6cd52&#xff1a;LIMIT \u6761\u6570 OFFSET \u8d77\u59cb\u7d22\u5f15<br \/>\nSELECT * FROM student LIMIT 2 OFFSET 0;  &#8212; \u7b49\u4ef7\u4e8e LIMIT 0,2<\/p>\n<p>\u5206\u9875\u516c\u5f0f&#xff1a;<\/p>\n<p>&#8212; pageSize &#061; \u6bcf\u9875\u6761\u6570  page &#061; \u5f53\u524d\u9875\u7801<br \/>\nSELECT * FROM student LIMIT (page &#8211; 1) * pageSize, pageSize;<\/p>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;\u7d22\u5f15\u548cid\u6ca1\u5173\u7cfb&#xff0c;\u662f\u5bf9WHERE\u7b5b\u9009\u540e\u7684\u7ed3\u679c\u4ece0\u5f00\u59cb\u7f16\u53f7\u3002WHERE\u3001ORDER BY\u3001LIMIT\u540c\u65f6\u7528\u65f6&#xff0c;\u987a\u5e8f\u56fa\u5b9a&#xff1a;WHERE \u2192 ORDER BY \u2192 LIMIT&#xff0c;LIMIT\u6c38\u8fdc\u653e\u6700\u540e\u3002<\/p>\n<h4>6.5 \u805a\u5408\u51fd\u6570<\/h4>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;\u805a\u5408\u51fd\u6570\u662f&#034;\u4e00\u5806\u6570\u636e\u51fa\u4e00\u4e2a\u7ed3\u679c&#034;\u2014\u2014\u628a\u591a\u884c\u6570\u636e\u805a\u5408\u6210\u5355\u4e2a\u503c\u3002<\/p>\n<table>\n<tr>\u51fd\u6570\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>MAX()<\/td>\n<td>\u6c42\u6700\u5927\u503c<\/td>\n<\/tr>\n<tr>\n<td>MIN()<\/td>\n<td>\u6c42\u6700\u5c0f\u503c<\/td>\n<\/tr>\n<tr>\n<td>AVG()<\/td>\n<td>\u6c42\u5e73\u5747\u503c<\/td>\n<\/tr>\n<tr>\n<td>SUM()<\/td>\n<td>\u6c42\u548c<\/td>\n<\/tr>\n<tr>\n<td>COUNT()<\/td>\n<td>\u7edf\u8ba1\u6570\u91cf&#xff08;\u4e0d\u7edf\u8ba1\u4e3aNULL\u7684\u8bb0\u5f55&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&#8212; \u666e\u901a\u67e5\u8be2&#xff1a;\u8fd4\u56de\u6240\u6709\u5e74\u9f84<br \/>\nSELECT age FROM student;<\/p>\n<p>&#8212; \u805a\u5408\u67e5\u8be2&#xff1a;\u8fd4\u56de\u4e00\u4e2a\u503c<br \/>\nSELECT MAX(age) FROM student;<br \/>\nSELECT MIN(age) FROM student;<br \/>\nSELECT AVG(age) FROM student;<br \/>\nSELECT SUM(age) FROM student;<\/p>\n<p>&#8212; COUNT\u533a\u522b<br \/>\nSELECT COUNT(*) FROM student;  &#8212; \u7edf\u8ba1\u6240\u6709\u884c\u6570<br \/>\nSELECT COUNT(age) FROM student; &#8212; \u4e0d\u7edf\u8ba1age\u4e3a\u7a7a\u7684\u8bb0\u5f55<\/p>\n<h4>6.6 GROUP BY \u2014 \u5206\u7ec4<\/h4>\n<p>&#8212; \u6309\u73ed\u7ea7\u5206\u7ec4&#xff0c;\u6c42\u6bcf\u73ed\u6700\u5927\u5e74\u9f84<br \/>\nSELECT MAX(age), cid FROM student GROUP BY cid;<\/p>\n<p>&#8212; \u5206\u7ec4\u524d\u7b5b\u9009&#xff08;WHERE&#xff09;<br \/>\nSELECT MAX(age), cid FROM student WHERE sex &#061; &#039;\u7537&#039; GROUP BY cid;<\/p>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;GROUP BY\u662f&#034;\u5148\u5206\u5806\u3001\u540e\u7edf\u8ba1&#034;\u3002\u5206\u7ec4\u524d\u7528WHERE\u8fc7\u6ee4\u539f\u8868\u6570\u636e&#xff0c;\u5206\u7ec4\u540e\u7528HAVING\u8fc7\u6ee4\u5206\u7ec4\u540e\u7684\u7ed3\u679c\u3002<\/p>\n<h4>6.7 HAVING \u2014 \u5206\u7ec4\u540e\u7b5b\u9009<\/h4>\n<p>&#8212; \u5206\u7ec4\u540e\u53ea\u7559\u73ed\u7ea7id&#061;2\u7684\u6570\u636e<br \/>\nSELECT MAX(age), cid FROM student WHERE sex &#061; &#039;\u7537&#039; GROUP BY cid HAVING cid &#061; 2;<\/p>\n<p>WHERE vs HAVING&#xff1a;<\/p>\n<table>\n<tr>\u5bf9\u6bd4WHEREHAVING<\/tr>\n<tbody>\n<tr>\n<td>\u6267\u884c\u65f6\u673a<\/td>\n<td>\u5206\u7ec4\u524d<\/td>\n<td>\u5206\u7ec4\u540e<\/td>\n<\/tr>\n<tr>\n<td>\u4f5c\u7528\u5bf9\u8c61<\/td>\n<td>\u539f\u8868\u8bb0\u5f55<\/td>\n<td>\u5206\u7ec4\u540e\u7684\u7ed3\u679c<\/td>\n<\/tr>\n<tr>\n<td>\u80fd\u5426\u7528\u805a\u5408\u51fd\u6570<\/td>\n<td>\u274c \u4e0d\u80fd<\/td>\n<td>\u2705 \u80fd<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>6.8 \u5b8c\u6574\u67e5\u8be2\u987a\u5e8f<\/h4>\n<p>SELECT \u5b57\u6bb5<br \/>\nFROM \u8868\u540d<br \/>\nWHERE \u6761\u4ef6           &#8212; 1. \u8fc7\u6ee4\u884c<br \/>\nGROUP BY \u5206\u7ec4\u5b57\u6bb5    &#8212; 2. \u5206\u7ec4<br \/>\nHAVING \u6761\u4ef6          &#8212; 3. \u8fc7\u6ee4\u5206\u7ec4<br \/>\nORDER BY \u6392\u5e8f\u5b57\u6bb5    &#8212; 4. \u6392\u5e8f<br \/>\nLIMIT \u8d77\u59cb, \u6570\u91cf;    &#8212; 5. \u5206\u9875<\/p>\n<p>\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;\u6267\u884c\u987a\u5e8f\u4e3a WHERE \u2192 GROUP BY \u2192 HAVING \u2192 ORDER BY \u2192 LIMIT&#xff0c;\u5404\u5b50\u53e5\u987a\u5e8f\u4e0d\u80fd\u4e71\u3002<\/p>\n<h3>\u9644\u5f55\u4e00&#xff1a;\u5b8c\u6574SQL\u793a\u4f8b&#xff08;ok.sql&#xff09;<\/h3>\n<p>&#8212; \u67e5\u627e<br \/>\nSELECT id,name,age,sex FROM student;<br \/>\nSELECT * FROM student;<\/p>\n<p>&#8212; \u6dfb\u52a0<br \/>\nINSERT INTO student(name,age,sex) VALUES(&#039;\u68a8\u82b1&#039;,25,&#039;\u5973&#039;);<\/p>\n<p>&#8212; \u4fee\u6539<br \/>\nUPDATE student SET name&#061;&#039;lili12&#039;, age&#061;30 WHERE id&#061;4;<\/p>\n<p>&#8212; \u5220\u9664<br \/>\nDELETE FROM student WHERE id&#061;7;<\/p>\n<p>&#8212; \u67e5\u6570\u91cf<br \/>\nSELECT COUNT(*) FROM student;<\/p>\n<p>&#8212; \u57fa\u7840\u67e5\u8be2<br \/>\nSELECT * FROM student WHERE name&#061;&#039;\u68a8\u82b1&#039; AND sex&#061;&#039;\u7537&#039;;<\/p>\n<p>&#8212; \u53bb\u91cd<br \/>\nSELECT DISTINCT age FROM student;<\/p>\n<p>&#8212; \u522b\u540d<br \/>\nSELECT age FROM student s1;<\/p>\n<p>&#8212; \u6bd4\u8f83\u8fd0\u7b97\u7b26<br \/>\nSELECT * FROM student WHERE age &lt;&gt; 24;<\/p>\n<p>&#8212; IN \/ BETWEEN<br \/>\nSELECT * FROM student WHERE age IN(18,31,28);<br \/>\nSELECT * FROM student WHERE age BETWEEN 18 AND 28;<\/p>\n<p>&#8212; \u903b\u8f91\u8fd0\u7b97\u7b26<br \/>\nSELECT * FROM student WHERE age&gt;18 AND age&lt;&#061;28 AND name&#061;&#039;\u674e\u56db&#039;;<br \/>\nSELECT * FROM student WHERE age&gt;30 OR name&#061;&#039;\u674e\u56db&#039;;<\/p>\n<p>&#8212; NOT IN \/ IS NOT NULL<br \/>\nSELECT * FROM student WHERE age NOT IN(18,31,28);<br \/>\nSELECT * FROM student WHERE age IS NOT NULL;<\/p>\n<p>&#8212; \u6a21\u7cca\u67e5\u627e<br \/>\nSELECT * FROM student WHERE name LIKE &#039;%a%&#039;;<\/p>\n<p>&#8212; \u5206\u9875\u67e5\u8be2<br \/>\nSELECT * FROM student LIMIT 0,2;<\/p>\n<p>&#8212; \u6392\u5e8f<br \/>\nSELECT * FROM student ORDER BY birth DESC;<\/p>\n<p>&#8212; \u7ec4\u5408\u67e5\u8be2<br \/>\nSELECT * FROM student WHERE sex&#061;&#039;\u7537&#039; ORDER BY birth DESC LIMIT 0,2;<\/p>\n<p>&#8212; \u805a\u5408\u51fd\u6570<br \/>\nSELECT MAX(age) FROM student;<br \/>\nSELECT COUNT(*) FROM student;<br \/>\nSELECT COUNT(age) FROM student;<\/p>\n<p>&#8212; \u5206\u7ec4<br \/>\nSELECT MAX(age), cid FROM student GROUP BY cid;<\/p>\n<p>&#8212; WHERE &#043; GROUP BY &#043; HAVING &#043; LIMIT<br \/>\nSELECT MAX(age), cid FROM student WHERE sex&#061;&#039;\u7537&#039; GROUP BY cid HAVING cid&#061;2 LIMIT 0,1;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c\u4e00\u90e8\u5206&#xff1a;\u6570\u636e\u5e93\u57fa\u78401.1 \u4ec0\u4e48\u662f\u6570\u636e\u5e93\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;\u6570\u636e\u5e93\u662f\u957f\u671f\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u5185\u7684\u3001\u6709\u7ec4\u7ec7\u7684\u3001\u53ef\u5171\u4eab\u7684\u6570\u636e\u96c6\u5408&#xff0c;\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u6587\u4ef6\u7cfb\u7edf\u3002\u548cExcel\u4e0d\u540c&#xff0c;Excel\u968f\u4fbf\u585e\u6570\u636e\u6ca1\u683c\u5f0f\u7ea6\u675f&#xff0c;\u800c\u6570\u636e\u5e93\u5fc5\u987b\u6309\u63d0\u524d\u8bbe\u597d\u7684\u7279\u5b9a\u683c\u5f0f\u5b58\u6570\u636e\u3002\u6570\u636e\u5e93 vs Excel&#xff1a;\u5bf9\u6bd4Excel\u6570\u636e\u5e93\u6570\u636e\u7ea6\u675f\u65e0\u683c\u5f0f\u9650\u5236\u5fc5\u987b\u7b26\u5408\u9884\u8bbe\u8868\u7ed3\u6784\u6570\u636e\u91cf\u9002\u5408\u5c0f\u6570\u636e\u652f\u6301\u6d77\u91cf\u6570\u636e\u5e76\u53d1\u8bbf\u95ee\u5f31\u5f3a\u6570\u636e\u89c4\u8303\u4e0d\u4e25\u683c\u4e25\u683c1.2 \u6570\u636e\u5e93\u5206\u7c7b\u7c7b\u578b\u8bf4\u660e\u4ee3\u8868\u4ea7<\/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],"topic":[],"class_list":["post-100516","post","type-post","status-publish","format-standard","hentry","category-server","tag-sql"],"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\u4e0eSQL\u8bed\u8a00\uff1a\u4ece\u6570\u636e\u7c7b\u578b\u5230DQL\u67e5\u8be2\u6838\u5fc3 - \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\/100516.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\u4e0eSQL\u8bed\u8a00\uff1a\u4ece\u6570\u636e\u7c7b\u578b\u5230DQL\u67e5\u8be2\u6838\u5fc3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u7b2c\u4e00\u90e8\u5206&#xff1a;\u6570\u636e\u5e93\u57fa\u78401.1 \u4ec0\u4e48\u662f\u6570\u636e\u5e93\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;\u6570\u636e\u5e93\u662f\u957f\u671f\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u5185\u7684\u3001\u6709\u7ec4\u7ec7\u7684\u3001\u53ef\u5171\u4eab\u7684\u6570\u636e\u96c6\u5408&#xff0c;\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u6587\u4ef6\u7cfb\u7edf\u3002\u548cExcel\u4e0d\u540c&#xff0c;Excel\u968f\u4fbf\u585e\u6570\u636e\u6ca1\u683c\u5f0f\u7ea6\u675f&#xff0c;\u800c\u6570\u636e\u5e93\u5fc5\u987b\u6309\u63d0\u524d\u8bbe\u597d\u7684\u7279\u5b9a\u683c\u5f0f\u5b58\u6570\u636e\u3002\u6570\u636e\u5e93 vs Excel&#xff1a;\u5bf9\u6bd4Excel\u6570\u636e\u5e93\u6570\u636e\u7ea6\u675f\u65e0\u683c\u5f0f\u9650\u5236\u5fc5\u987b\u7b26\u5408\u9884\u8bbe\u8868\u7ed3\u6784\u6570\u636e\u91cf\u9002\u5408\u5c0f\u6570\u636e\u652f\u6301\u6d77\u91cf\u6570\u636e\u5e76\u53d1\u8bbf\u95ee\u5f31\u5f3a\u6570\u636e\u89c4\u8303\u4e0d\u4e25\u683c\u4e25\u683c1.2 \u6570\u636e\u5e93\u5206\u7c7b\u7c7b\u578b\u8bf4\u660e\u4ee3\u8868\u4ea7\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/100516.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-04T11:04:52+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\/100516.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/100516.html\",\"name\":\"MySQL\u6570\u636e\u5e93\u4e0eSQL\u8bed\u8a00\uff1a\u4ece\u6570\u636e\u7c7b\u578b\u5230DQL\u67e5\u8be2\u6838\u5fc3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-04T11:04:52+00:00\",\"dateModified\":\"2026-09-04T11:04:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/100516.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/100516.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/100516.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\u4e0eSQL\u8bed\u8a00\uff1a\u4ece\u6570\u636e\u7c7b\u578b\u5230DQL\u67e5\u8be2\u6838\u5fc3\"}]},{\"@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\u4e0eSQL\u8bed\u8a00\uff1a\u4ece\u6570\u636e\u7c7b\u578b\u5230DQL\u67e5\u8be2\u6838\u5fc3 - \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\/100516.html","og_locale":"zh_CN","og_type":"article","og_title":"MySQL\u6570\u636e\u5e93\u4e0eSQL\u8bed\u8a00\uff1a\u4ece\u6570\u636e\u7c7b\u578b\u5230DQL\u67e5\u8be2\u6838\u5fc3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u7b2c\u4e00\u90e8\u5206&#xff1a;\u6570\u636e\u5e93\u57fa\u78401.1 \u4ec0\u4e48\u662f\u6570\u636e\u5e93\u2b50 \u8001\u5e08\u5f3a\u8c03&#xff1a;\u6570\u636e\u5e93\u662f\u957f\u671f\u5b58\u50a8\u5728\u8ba1\u7b97\u673a\u5185\u7684\u3001\u6709\u7ec4\u7ec7\u7684\u3001\u53ef\u5171\u4eab\u7684\u6570\u636e\u96c6\u5408&#xff0c;\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u6587\u4ef6\u7cfb\u7edf\u3002\u548cExcel\u4e0d\u540c&#xff0c;Excel\u968f\u4fbf\u585e\u6570\u636e\u6ca1\u683c\u5f0f\u7ea6\u675f&#xff0c;\u800c\u6570\u636e\u5e93\u5fc5\u987b\u6309\u63d0\u524d\u8bbe\u597d\u7684\u7279\u5b9a\u683c\u5f0f\u5b58\u6570\u636e\u3002\u6570\u636e\u5e93 vs Excel&#xff1a;\u5bf9\u6bd4Excel\u6570\u636e\u5e93\u6570\u636e\u7ea6\u675f\u65e0\u683c\u5f0f\u9650\u5236\u5fc5\u987b\u7b26\u5408\u9884\u8bbe\u8868\u7ed3\u6784\u6570\u636e\u91cf\u9002\u5408\u5c0f\u6570\u636e\u652f\u6301\u6d77\u91cf\u6570\u636e\u5e76\u53d1\u8bbf\u95ee\u5f31\u5f3a\u6570\u636e\u89c4\u8303\u4e0d\u4e25\u683c\u4e25\u683c1.2 \u6570\u636e\u5e93\u5206\u7c7b\u7c7b\u578b\u8bf4\u660e\u4ee3\u8868\u4ea7","og_url":"https:\/\/www.wsisp.com\/helps\/100516.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-04T11:04:52+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\/100516.html","url":"https:\/\/www.wsisp.com\/helps\/100516.html","name":"MySQL\u6570\u636e\u5e93\u4e0eSQL\u8bed\u8a00\uff1a\u4ece\u6570\u636e\u7c7b\u578b\u5230DQL\u67e5\u8be2\u6838\u5fc3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-04T11:04:52+00:00","dateModified":"2026-09-04T11:04:52+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/100516.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/100516.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/100516.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\u4e0eSQL\u8bed\u8a00\uff1a\u4ece\u6570\u636e\u7c7b\u578b\u5230DQL\u67e5\u8be2\u6838\u5fc3"}]},{"@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\/100516","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=100516"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/100516\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=100516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=100516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=100516"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=100516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}