{"id":800,"date":"2025-01-16T20:15:54","date_gmt":"2025-01-16T12:15:54","guid":{"rendered":"https:\/\/eve2333.top\/?p=800"},"modified":"2025-01-16T20:15:54","modified_gmt":"2025-01-16T12:15:54","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e5%85%a5%e9%97%a8%e5%88%b0%e5%a4%a7%e8%9b%87%e5%b0%9a%e7%a1%85%e8%b0%b7%e5%ae%8b%e7%ba%a2%e5%ba%b7%e8%80%81%e5%b8%88%e7%ac%94%e8%ae%b0-%e5%9f%ba%e7%a1%80%e7%af%87-part","status":"publish","type":"post","link":"https:\/\/eve2333.top\/?p=800","title":{"rendered":"MySQL\u6570\u636e\u5e93\u5165\u95e8\u5230\u5927\u86c7\u5c1a\u7845\u8c37\u5b8b\u7ea2\u5eb7\u8001\u5e08\u7b14\u8bb0 \u57fa\u7840\u7bc7 part 4"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">&nbsp;\u7b2c04\u7ae0_\u8fd0\u7b97\u7b26<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u7b97\u672f\u8fd0\u7b97\u7b26<\/h3>\n\n\n\n<p>\u7b97\u672f\u8fd0\u7b97\u7b26\u4e3b\u8981\u7528\u4e8e\u6570\u5b66\u8fd0\u7b97\uff0c\u5176\u53ef\u4ee5\u8fde\u63a5\u8fd0\u7b97\u7b26\u524d\u540e\u7684\u4e24\u4e2a\u6570\u503c\u6216\u8868\u8fbe\u5f0f\uff0c\u5bf9\u6570\u503c\u6216\u8868\u8fbe\u5f0f\u8fdb\u884c\u52a0 \uff08+\uff09\u3001\u51cf\uff08-\uff09\u3001\u4e58\uff08*\uff09\u3001\u9664\uff08\/\uff09\u548c\u53d6\u6a21\uff08%\uff09\u8fd0\u7b97\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#1.\u7b97\u672f\u8fd0\u7b97\u7b26\uff1a\n\nSELECT 100,100+0\uff0c100-0\uff0c100 +50\uff0c100+50*30,100+35.5\uff0c100-35.5\nFROM DUAL;\n\n#\u5728SQL\u4e2d\uff0c+\u6ca1\u6709\u8fde\u63a5\u7684\u4f5c\u7528\uff0c\u5c31\u8868\u793a\u52a0\u6cd5\u8fd0\u7b97\u3002\u6b64\u65f6\uff0c\u4f1a\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u503c\uff08\u9690\u5f0f\u8f6c\u6362\uff09\nSELECT 100+'1'#\u5728Java\u8bed\u8a00\u4e2d\uff0c\u7ed3\u679c\u662f\uff1a1001\u3002\nFROM DUAL;\n\nSELECT100+'a'#\u6b64\u65f6\u5c06'a'\u770b\u505a0\u5904\u7406\nFROM DUAL;\n\nSELECT 100 + NULL#null\u503c\u53c2\u4e0e\u8fd0\u7b97\uff0c\u7ed3\u679c\u4e3anull\nFROM DUAL;\n\nSELECT 100,100*1,100*1.0,100\/1.0,100\/2,\n100+2*5\/2,100\/3,100 DIV 0 #\u5206\u6bcd\u4e3a0,\u7ed3\u679c\u662fnull\nFROM DUAL;<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ul class=\"wp-block-list\">\n<li>\u4e00\u4e2a\u6574\u6570\u7c7b\u578b\u7684\u503c\u5bf9\u6574\u6570\u8fdb\u884c\u52a0\u6cd5\u548c\u51cf\u6cd5\u64cd\u4f5c\uff0c\u7ed3\u679c\u8fd8\u662f\u4e00\u4e2a\u6574\u6570\uff1b<\/li>\n\n\n\n<li>\u4e00\u4e2a\u6574\u6570\u7c7b\u578b\u7684\u503c\u5bf9\u6d6e\u70b9\u6570\u8fdb\u884c\u52a0\u6cd5\u548c\u51cf\u6cd5\u64cd\u4f5c\uff0c\u7ed3\u679c\u662f\u4e00\u4e2a\u6d6e\u70b9\u6570\uff1b<\/li>\n\n\n\n<li>\u52a0\u6cd5\u548c\u51cf\u6cd5\u7684\u4f18\u5148\u7ea7\u76f8\u540c\uff0c\u8fdb\u884c\u5148\u52a0\u540e\u51cf\u64cd\u4f5c\u4e0e\u8fdb\u884c\u5148\u51cf\u540e\u52a0\u64cd\u4f5c\u7684\u7ed3\u679c\u662f\u4e00\u6837\u7684\uff1b<\/li>\n\n\n\n<li>\u5728Java\u4e2d\uff0c+\u7684\u5de6\u53f3\u4e24\u8fb9\u5982\u679c\u6709\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u8868\u793a\u5b57\u7b26\u4e32\u7684\u62fc\u63a5\u3002\u4f46\u662f\u5728MySQL\u4e2d+\u53ea\u8868\u793a\u6570 \u503c\u76f8\u52a0\u3002\u5982\u679c\u9047\u5230\u975e\u6570\u503c\u7c7b\u578b\uff0c\u5148\u5c1d\u8bd5\u8f6c\u6210\u6570\u503c\uff0c\u5982\u679c\u8f6c\u5931\u8d25\uff0c\u5c31\u63090\u8ba1\u7b97\u3002\uff08\u8865\u5145\uff1aMySQL \u4e2d\u5b57\u7b26\u4e32\u62fc\u63a5\u8981\u4f7f\u7528\u5b57\u7b26\u4e32\u51fd\u6570CONCAT()\u5b9e\u73b0\uff09<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">&nbsp;2. \u6bd4\u8f83\u8fd0\u7b97\u7b26<\/h3>\n\n\n\n<p>\u6bd4\u8f83\u8fd0\u7b97\u7b26\u7528\u6765\u5bf9\u8868\u8fbe\u5f0f\u5de6\u8fb9\u7684\u64cd\u4f5c\u6570\u548c\u53f3\u8fb9\u7684\u64cd\u4f5c\u6570\u8fdb\u884c\u6bd4\u8f83\uff0c\u6bd4\u8f83\u7684\u7ed3\u679c\u4e3a\u771f\u5219\u8fd4\u56de1\uff0c\u6bd4\u8f83\u7684\u7ed3\u679c \u4e3a\u5047\u5219\u8fd4\u56de0\uff0c\u5176\u4ed6\u60c5\u51b5\u5219\u8fd4\u56deNULL\u3002<\/p>\n\n\n\n<p>\u6bd4\u8f83\u8fd0\u7b97\u7b26\u7ecf\u5e38\u88ab\u7528\u6765\u4f5c\u4e3aSELECT\u67e5\u8be2\u8bed\u53e5\u7684\u6761\u4ef6\u6765\u4f7f\u7528\uff0c\u8fd4\u56de\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c\u8bb0\u5f55\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#2.1 = &lt;=&gt; &lt;&gt; != &lt; &lt;= &gt; &gt;=\n\n#=\u7684\u4f7f\u7528\nSELECT 1=2 ,1!= 2 ,1='1' ,1='a' ,0='a'  #\u5b57\u7b26\u4e32\u5b58\u5728\u9690\u5f0f\u8f6c\u6362\u3002\u5982\u679c\u8f6c\u6362\u6570\u503c\u4e0d\u6210\u529f\uff0c\u5219\u770b\u505a0\nFROM DUAL;\n\nSELECT 'a' = 'a','ab'='ab','a'='b' #\u4e24\u8fb9\u90fd\u662f\u5b57\u7b26\u4e32\u7684\u8bdd\uff0c\u5219\u6309\u7167ANSI\u7684\u6bd4\u8f83\u89c4\u5219\u8fdb\u884c\u6bd4\u8f83\u3002\nFROM DUAL;\n\nSELECT 1=NULL ,NULL=NULL# \u53ea\u8981\u6709null\u53c2\u4e0e\u5224\u65ad\uff0c\u7ed3\u679c\u5c31\u4e3anul1\nFROM DUAL;\n\nSELECT last_name,salary,commission_pct\nFROM emplyees\n#where salary=6000;\nWHERE commission_pct = NULL #\u6b64\u65f6\u6362\u884c\u4e0d\u4f1a\u6709\u4efb\u4f55\u7ed3\u679c<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#&lt;=&gt;\uff1a\u5b89\u5168\u7b49\u4e8e\u3002\u8bb0\u5fc6\u6280\u5de7\uff1a\u4e3aNULL\u800c\u751f\u3002\nSELECT 1&lt;=&gt;2 ,1&lt;=&gt;'1' ,1&lt;=&gt;'a' ,0&lt;=&gt;'a'\nFROM DUAL;\n\nSELECT 1&lt;=&gt;NULL\uff0cNULL&lt;=&gt; NULL\nFROM DUAL;\n\n#\u7ec3\u4e60\uff1a\u67e5\u8be2\u8868\u4e2dcommission_pct\u4e3anull\u7684\u6570\u636e\u6709\u54ea\u4e9b\nSELEcT last_name,salary,commission_pct\nFROM employees\nWHERE commission_pct &lt;=&gt; NULL;<\/code><\/pre>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"15\" src=\"blob:https:\/\/eve2333.top\/0e9a50b4-fac3-4c7a-8ea7-f89a135e5967\" width=\"15\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u4e0d\u7b49\u4e8e\u8fd0\u7b97\u7b26 \u4e0d\u7b49\u4e8e\u8fd0\u7b97\u7b26\uff08&lt;&gt;\u548c!=\uff09\u7528\u4e8e\u5224\u65ad\u4e24\u8fb9\u7684\u6570\u5b57\u3001\u5b57\u7b26\u4e32\u6216\u8005\u8868\u8fbe\u5f0f\u7684\u503c\u662f\u5426\u4e0d\u76f8\u7b49\uff0c\n\u5982\u679c\u4e0d\u76f8\u7b49\u5219\u8fd4\u56de1\uff0c\u76f8\u7b49\u5219\u8fd4\u56de0\u3002\u4e0d\u7b49\u4e8e\u8fd0\u7b97\u7b26\u4e0d\u80fd\u5224\u65adNULL\u503c\u3002\u5982\u679c\u4e24\u8fb9\u7684\u503c\u6709\u4efb\u610f\u4e00\u4e2a\u4e3aNULL\uff0c\n\u6216\u4e24\u8fb9\u90fd\u4e3aNULL\uff0c\u5219\u7ed3\u679c\u4e3aNULL\u3002 SQL\u8bed\u53e5\u793a\u4f8b\u5982\u4e0b\uff1a\n\nSELECT 1 &lt;&gt; 1, 1 != 2, 'a' != 'b', (3+4) &lt;&gt; (2+6), 'a' != NULL, NULL &lt;&gt; NULL;\n\n +--------+--------+------------+----------------+-------------+--------------+\n | 1 &lt;&gt; 1 | 1 != 2 | 'a' != 'b' | (3+4) &lt;&gt; (2+6) | 'a' != NULL | NULL &lt;&gt; NULL |\n +--------+--------+------------+----------------+-------------+--------------+\n |      0 |   1    |       1    |            1   |     NULL    |         NULL |\n +--------+--------+------------+----------------+-------------+--------------+\n 1 row in set (0.00 sec)<\/code><\/pre>\n\n\n\n<p>&nbsp;\u975e\u7b26\u53f7\u7c7b\u578b\u7684\u8fd0\u7b97\u7b26\uff1a<\/p>\n\n\n\n<p><img decoding=\"async\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/902444be7bc940dd821883ac53c14117.png\" alt=\"\"><\/p>\n\n\n\n<p>\u7a7a\u8fd0\u7b97\u7b26 \u7a7a\u8fd0\u7b97\u7b26\uff08IS NULL\u6216\u8005ISNULL\uff09\u5224\u65ad\u4e00\u4e2a\u503c\u662f\u5426\u4e3aNULL\uff0c\u5982\u679c\u4e3aNULL\u5219\u8fd4\u56de1\uff0c\u5426\u5219\u8fd4\u56de 0\u3002 SQL\u8bed\u53e5\u793a\u4f8b\u5982\u4e0b\uff1a&nbsp;<br>\u975e\u7a7a\u8fd0\u7b97\u7b26 \u975e\u7a7a\u8fd0\u7b97\u7b26\uff08IS NOT NULL\uff09\u5224\u65ad\u4e00\u4e2a\u503c\u662f\u5426\u4e0d\u4e3aNULL\uff0c\u5982\u679c\u4e0d\u4e3aNULL\u5219\u8fd4\u56de1\uff0c\u5426\u5219\u8fd4 \u56de0\u3002 SQL\u8bed\u53e5\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#IS NULL \\ IS NOT NULL \\ ISNULL\n#\u7ec3\u4e60\uff1a\u67e5\u8be2\u8868\u4e2dcommission_pct\u4e3anull\u7684\u6570\u636e\u6709\u54ea\u4e9b\nSELECT last_name,salary,commission_pct\nFROM employees\nWHERE commission_pct IS NULL;\n#\u6216\nSELECT last_name,salary,commission_pct\nFROM employees\nWHERE ISNULL(commission_pct);\n\n#\u7ec3\u4e60\uff1a\u67e5\u8be2\u8868\u4e2dcommission_pct\u4e0d\u4e3anull\u7684\u6570\u636e\u6709\u54ea\u4e9b\nSELECT last_name,salary,commission_pct\nFROM employees\nWHERE commission_pct IS NOT NULL;\n#\u6216\nSELECT last_name,salary,commission_pct\nFROM employees\nWHERE NOT commission_pct &lt;=&gt; NULL;<\/code><\/pre>\n\n\n\n<p>\u8bed\u6cd5\u683c\u5f0f\u4e3a\uff1aLEAST(\u503c1\uff0c\u503c2\uff0c...\uff0c\u503cn)\u3002\u5176\u4e2d\uff0c\u201c\u503cn\u201d\u8868\u793a\u53c2\u6570\u5217\u8868\u4e2d\u6709n\u4e2a\u503c\u3002\u5728\u6709 \u4e24\u4e2a\u6216\u591a\u4e2a\u53c2\u6570\u7684\u60c5\u51b5\u4e0b\uff0c\u8fd4\u56de\u6700\u5c0f\u503c&nbsp;&nbsp;\u7531\u7ed3\u679c\u53ef\u4ee5\u770b\u5230\uff0c\u5f53\u53c2\u6570\u662f\u6574\u6570\u6216\u8005\u6d6e\u70b9\u6570\u65f6\uff0cLEAST\u5c06\u8fd4\u56de\u5176\u4e2d\u6700\u5c0f\u7684\u503c\uff1b\u5f53\u53c2\u6570\u4e3a\u5b57\u7b26\u4e32\u65f6\uff0c\u8fd4\u56de\u5b57 \u6bcd\u8868\u4e2d\u987a\u5e8f\u6700\u9760\u524d\u7684\u5b57\u7b26\uff1b\u5f53\u6bd4\u8f83\u503c\u5217\u8868\u4e2d\u6709NULL\u65f6\uff0c\u4e0d\u80fd\u5224\u65ad\u5927\u5c0f\uff0c\u8fd4\u56de\u503c\u4e3aNULL\u3002<\/p>\n\n\n\n<p>\u6700\u5927\u503c\u8fd0\u7b97\u7b26 \u8bed\u6cd5\u683c\u5f0f\u4e3a\uff1aGREATEST(\u503c1\uff0c\u503c2\uff0c...\uff0c\u503cn)\u3002\u5176\u4e2d\uff0cn\u8868\u793a\u53c2\u6570\u5217\u8868\u4e2d\u6709n\u4e2a\u503c\u3002\u5f53\u6709 \u4e24\u4e2a\u6216\u591a\u4e2a\u53c2\u6570\u65f6\uff0c\u8fd4\u56de\u503c\u4e3a\u6700\u5927\u503c\u3002\u5047\u5982\u4efb\u610f\u4e00\u4e2a\u81ea\u53d8\u91cf\u4e3aNULL\uff0c\u5219GREATEST()\u7684\u8fd4\u56de\u503c\u4e3aNULL\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#LEAST() \\  GREATEST\nSELECT LEAST('g','b','t','m'),GREATEST('g','b','t','m')\nFROM DUAL;\n\nSELECT LEAST\uff08first_name,last_name),LEAST(LENGTH\uff08first_name),LENGTH(last_name))\nFROM employees;\n\n#BETWEEN \u6761\u4ef6\u4e0b\u754c1 AND \u6761\u4ef6\u4e0a\u754c2\uff08\u67e5\u8be2\u6761\u4ef61\u548c\u6761\u4ef62\u8303\u56f4\u5185\u7684\u6570\u636e\uff0c\u5305\u542b\u8fb9\u754c\uff09\n#\u67e5\u8be2\u5de5\u8d44\u57286000\u52308000\u7684\u5458\u5de5\u4fe1\u606f\nSELECT employee_id,last_name,salary\nFROM employees\n#where salarybetween 6000 and 8000;\nWHERE salary&gt;=6000 &amp;&amp; salary&lt;=8000;\n\n#\u4ea4\u63626000\u548c8000\u4e4b\u540e\uff0c\u67e5\u8be2\u4e0d\u5230\u6570\u636e\nSELECT employee_id,last_name,salary\nFROM employees\nWHERE salary BETWEEN 8000 AND 6000;\n\n#\u67e5\u8be2\u5de5\u8d44\u4e0d\u57286000\u52308000\u7684\u5458\u5de5\u4fe1\u606f\nSELECT employee_id,last_name,salary\nFROM employees\nWHERE salary NOT BETWEEN 6000 AND 8000;\n#where salary&lt; 6000 or salary&gt;8000;<\/code><\/pre>\n\n\n\n<p>\u7531\u7ed3\u679c\u53ef\u4ee5\u770b\u5230\uff0c\u5f53\u53c2\u6570\u4e2d\u662f\u6574\u6570\u6216\u8005\u6d6e\u70b9\u6570\u65f6\uff0cGREATEST\u5c06\u8fd4\u56de\u5176\u4e2d\u6700\u5927\u7684\u503c\uff1b\u5f53\u53c2\u6570\u4e3a\u5b57\u7b26\u4e32\u65f6\uff0c \u8fd4\u56de\u5b57\u6bcd\u8868\u4e2d\u987a\u5e8f\u6700\u9760\u540e\u7684\u5b57\u7b26\uff1b\u5f53\u6bd4\u8f83\u503c\u5217\u8868\u4e2d\u6709NULL\u65f6\uff0c\u4e0d\u80fd\u5224\u65ad\u5927\u5c0f\uff0c\u8fd4\u56de\u503c\u4e3aNULL\u3002&nbsp; BETWEEN AND\u8fd0\u7b97\u7b26 BETWEEN\u8fd0\u7b97\u7b26\u4f7f\u7528\u7684\u683c\u5f0f\u901a\u5e38\u4e3aSELECT D FROM TABLE WHERE C BETWEEN A AND B\uff0c\u6b64\u65f6\uff0c\u5f53C\u5927\u4e8e\u6216\u7b49\u4e8eA\uff0c\u5e76\u4e14C\u5c0f\u4e8e\u6216\u7b49\u4e8eB\u65f6\uff0c\u7ed3\u679c\u4e3a1\uff0c\u5426\u5219\u7ed3\u679c\u4e3a0\u3002&nbsp;<\/p>\n\n\n\n<p>Dual\u662f\u4f2a\u8868<\/p>\n\n\n\n<p>IN\u8fd0\u7b97\u7b26 IN\u8fd0\u7b97\u7b26\u7528\u4e8e\u5224\u65ad\u7ed9\u5b9a\u7684\u503c\u662f\u5426\u662fIN\u5217\u8868\u4e2d\u7684\u4e00\u4e2a\u503c\uff0c\u5982\u679c\u662f\u5219\u8fd4\u56de1\uff0c\u5426\u5219\u8fd4\u56de0\u3002\u5982\u679c\u7ed9 \u5b9a\u7684\u503c\u4e3aNULL\uff0c\u6216\u8005IN\u5217\u8868\u4e2d\u5b58\u5728NULL\uff0c\u5219\u7ed3\u679c\u4e3aNULL\u3002<br>NOT IN\u8fd0\u7b97\u7b26 NOT IN\u8fd0\u7b97\u7b26\u7528\u4e8e\u5224\u65ad\u7ed9\u5b9a\u7684\u503c\u662f\u5426\u4e0d\u662fIN\u5217\u8868\u4e2d\u7684\u4e00\u4e2a\u503c\uff0c\u5982\u679c\u4e0d\u662fIN\u5217\u8868\u4e2d\u7684\u4e00 \u4e2a\u503c\uff0c\u5219\u8fd4\u56de1\uff0c\u5426\u5219\u8fd4\u56de0\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># in \uff08set\uff09\\ not in \uff08set)\n\n#\u7ec3\u4e60\uff1a\u67e5\u8be2\u90e8\u95e8\u4e3a10\uff0c20\uff0c30\u90e8\u95e8\u7684\u5458\u5de5\u4fe1\u606f\nSELECT last_name,salary,department_id\nFROM employees\n#where department_id=10 or department_id=20or department_id=30;\nWHERE department_id IN (10,20,30);\n\n#\u7ec3\u4e60\uff1a\u67e5\u8be2\u5de5\u8d44\u4e0d\u662f6000\uff0c7000\uff0c8000\u7684\u5458\u5de5\u4fe1\u606f\nSELECT last_name,salary,department_id\nFROM employees\nWHERE salary NOT IN (6000,7000,8000);<\/code><\/pre>\n\n\n\n<p>LIKE\u8fd0\u7b97\u7b26 LIKE\u8fd0\u7b97\u7b26\u4e3b\u8981\u7528\u6765\u5339\u914d\u5b57\u7b26\u4e32\uff0c\u901a\u5e38\u7528\u4e8e\u6a21\u7cca\u5339\u914d\uff0c\u5982\u679c\u6ee1\u8db3\u6761\u4ef6\u5219\u8fd4\u56de1\uff0c\u5426\u5219\u8fd4\u56de 0\u3002\u5982\u679c\u7ed9\u5b9a\u7684\u503c\u6216\u8005\u5339\u914d\u6761\u4ef6\u4e3aNULL\uff0c\u5219\u8fd4\u56de\u7ed3\u679c\u4e3aNULL\u3002 LIKE\u8fd0\u7b97\u7b26\u901a\u5e38\u4f7f\u7528\u5982\u4e0b\u901a\u914d\u7b26\uff1a<strong>&nbsp;\u201c%\u201d\uff1a\u5339\u914d0\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u3002 \u201c_\u201d\uff1a\u53ea\u80fd\u5339\u914d\u4e00\u4e2a\u5b57\u7b26\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#LIKE\uff1a\u6a21\u7cca\u67e5\u8be2\n# %\uff1a\u4ee3\u8868\u4e0d\u786e\u5b9a\u4e2a\u6570\u7684\u5b57\u7b26\uff080\u4e2a\uff0c1\u4e2a\uff0c\u6216\u591a\u4e2a\uff09\n\n#\u7ec3\u4e60\uff1a\u67e5\u8be2lastname\u4e2d\u5305\u542b\u5b57\u7b26'a'\u7684\u5458\u5de5\u4fe1\u606f\nSELECT last _name\nFROM employees\nWHERE last name LIKE '%a%'\uff1b\n\n#\u7ec3\u4e60\uff1a\u67e5\u8be2last_name\u4e2d\u4ee5\u5b57\u7b26'a'\u5f00\u5934\u7684\u5458\u5de5\u4fe1\u606f\nSELECT last_name\nFROM employees\nWHERE last_name LIKE '%a%'\n\n#\u7ec3\u4e60\uff1a\u67e5\u8be2lastname\u4e2d\u5305\u542b\u5b57\u7b26'a'\u4e14\u5305\u542b\u5b57\u7b26'e'\u7684\u5458\u5de5\u4fe1\u606f\n#\u5199\u6cd51\uff1a\nSELECT last_name\nFROM employees\nWHERE last_name LIKE '%a%' AND last_name LIKE '%e%';\n#\u5199\u6cd52\uff1a\nSELECT last_name\nFROMemployees\nWHERE last_name LIKE '%a%e%' OR last_name LIKE '%e%a%'\uff1b<\/code><\/pre>\n\n\n\n<p>_ \u4e0d\u786e\u5b9a\u7684\u7b26\u53f7<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u7ec3\u4e60\uff1a\u67e5\u8be2\u7b2c3\u4e2a\u5b57\u7b26\u662f'a'\u7684\u5458\u5de5\u4fe1\u606f\nSELEcT last_name\nFROM employees\nWHERE last_name LIKE '_a%';\n\n#\u7ec3\u4e60\uff1a\u67e5\u8be2\u7b2c2\u4e2a\u5b57\u7b26\u662f_\u4e14\u7b2c3\u4e2a\u5b57\u7b26\u662f'a'\u7684\u5458\u5de5\u4fe1\u606f\n#\u9700\u8981\u4f7f\u7528\u8f6c\u4e49\u5b57\u7b26\uff1a\nSELECT last_name\nFROM employees\nWHERE last_name LIKE '_\\_a%';\n\n#\u6216\u8005(\u4e86\u89e3)\nSELECT last_name\nFROM employees\nWHERE last_name LIKE '_$_a%' ESCAPE '$';\n\n\u56de\u907f\u7279\u6b8a\u7b26\u53f7\u7684\uff1a\u4f7f\u7528\u8f6c\u4e49\u7b26\u3002\u4f8b\u5982\uff1a\u5c06&#91;%]\u8f6c\u4e3a&#91;$%]\u3001&#91;]\u8f6c\u4e3a&#91;$]\uff0c\u7136\u540e\u518d\u52a0\u4e0a&#91;ESCAPE '$']\u5373\u53ef\u3002\nSELECT job_id\nFROM   jobs\nWHERE  job_id LIKE 'IT\\_%';\n\u5982\u679c\u4f7f\u7528\\\u8868\u793a\u8f6c\u4e49\uff0c\u8981\u7701\u7565ESCAPE\u3002\u5982\u679c\u4e0d\u662f\\\uff0c\u5219\u8981\u52a0\u4e0aESCAPE\u3002\nSELECT job_id\nFROM   jobs\nWHERE  job_id LIKE 'IT$_%' escape '$';\nSQL\u6807\u51c6\u91cc\u662f\u8981\u52a0\u4e0aESCAPE\u7684\uff0c\u53ef\u60dcDBMS\u6ca1\u6709\u9075\u5b88<\/code><\/pre>\n\n\n\n<p>REGEXP\u8fd0\u7b97\u7b26 ( \u770b\u770b\u5c31\u597d,\u6ca1\u4eba\u5728\u6570\u636e\u5e93\u91cc\u505a\u6b63\u5219 ) REGEXP\u8fd0\u7b97\u7b26\u7528\u6765\u5339\u914d\u5b57\u7b26\u4e32\uff0c\u8bed\u6cd5\u683c\u5f0f\u4e3a\uff1a expr REGEXP \u5339\u914d\u6761\u4ef6 \u3002\u5982\u679cexpr\u6ee1\u8db3\u5339\u914d\u6761\u4ef6\uff0c\u8fd4\u56de 1\uff1b\u5982\u679c\u4e0d\u6ee1\u8db3\uff0c\u5219\u8fd4\u56de0\u3002\u82e5expr\u6216\u5339\u914d\u6761\u4ef6\u4efb\u610f\u4e00\u4e2a\u4e3aNULL\uff0c\u5219\u7ed3\u679c\u4e3aNULL\u3002<\/p>\n\n\n\n<p>REGEXP\u8fd0\u7b97\u7b26\u5728\u8fdb\u884c\u5339\u914d\u65f6\uff0c\u5e38\u7528\u7684\u6709\u4e0b\u9762\u51e0\u79cd\u901a\u914d\u7b26\uff1a<br>\uff081\uff09\u2018^\u2019\u5339\u914d\u4ee5\u8be5\u5b57\u7b26\u540e\u9762\u7684\u5b57\u7b26\u5f00\u5934\u7684\u5b57\u7b26\u4e32\u3002<br>\uff082\uff09\u2018$\u2019\u5339\u914d\u4ee5\u8be5\u5b57\u7b26\u524d\u9762\u7684\u5b57\u7b26\u7ed3\u5c3e\u7684\u5b57\u7b26\u4e32\u3002<br>\uff083\uff09\u2018.\u2019\u5339\u914d\u4efb\u4f55\u4e00\u4e2a\u5355\u5b57\u7b26\u3002<br>\uff084\uff09\u201c[...]\u201d\u5339\u914d\u5728\u65b9\u62ec\u53f7\u5185\u7684\u4efb\u4f55\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\u201c[abc]\u201d\u5339\u914d\u201ca\u201d\u6216\u201cb\u201d\u6216\u201cc\u201d\u3002\u4e3a\u4e86\u547d\u540d\u5b57\u7b26\u7684\u8303\u56f4\uff0c\u4f7f\u7528\u4e00 \u4e2a\u2018-\u2019\u3002\u201c[a-z]\u201d\u5339\u914d\u4efb\u4f55\u5b57\u6bcd\uff0c\u800c\u201c[0-9]\u201d\u5339\u914d\u4efb\u4f55\u6570\u5b57\u3002<br>\uff085\uff09\u2018*\u2019\u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u5728\u5b83\u524d\u9762\u7684\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\u201cx*\u201d\u5339\u914d\u4efb\u4f55\u6570\u91cf\u7684\u2018x\u2019\u5b57\u7b26\uff0c\u201c[0-9]*\u201d\u5339\u914d\u4efb\u4f55\u6570\u91cf\u7684\u6570\u5b57\uff0c \u800c\u201c*\u201d\u5339\u914d\u4efb\u4f55\u6570\u91cf\u7684\u4efb\u4f55\u5b57\u7b26\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># REGEXP \\ RLIKE\uff1a\u6b63\u5219\u8868\u8fbe\u5f0f\n\nSELECT 'shkstart' REGEXP '^shk' 'shkstart' REGEXP 't$' 'shkstart' REGEXP 'hk'\nFROM DUAL;\n\nSELECT 'atguigu' REGEXP 'gu.gu' ,'atguigu' REGEXP '&#91;ab]'\nFROM DUAL;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u903b\u8f91\u8fd0\u7b97\u7b26<\/h3>\n\n\n\n<p>\u903b\u8f91\u8fd0\u7b97\u7b26\u4e3b\u8981\u7528\u6765\u5224\u65ad\u8868\u8fbe\u5f0f\u7684\u771f\u5047\uff0c\u5728MySQL\u4e2d\uff0c\u903b\u8f91\u8fd0\u7b97\u7b26\u7684\u8fd4\u56de\u7ed3\u679c\u4e3a1\u30010\u6216\u8005NULL\u3002 MySQL\u4e2d\u652f\u63014\u79cd\u903b\u8f91\u8fd0\u7b97\u7b26\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>\u8fd0\u7b97\u7b26<\/td><td>\u4f5c\u7528<\/td><td>\u793a\u4f8b<\/td><\/tr><tr><td>NOT\u6216\uff01<\/td><td>\u903b\u8f91\u975e<\/td><td>SELECT NOT A<\/td><\/tr><tr><td>AND\u6216&amp;&amp;<\/td><td>\u903b\u8f91\u4e0e<\/td><td>SELECT A AND B<br>SELECT A &amp;&amp; B<\/td><\/tr><tr><td>OR\u6216II<\/td><td>\u903b\u8f91\u6216<\/td><td>SELECT A OR B SELECT A || B<\/td><\/tr><tr><td>XOR<\/td><td>\u903b\u8f91\u5f02\u6216<\/td><td>SELECT A XOR B<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>#3.\u903b\u8f91\u8fd0\u7b97\u7b26\uff1aOR || AND &amp;&amp; NOT\uff01XOR\n\n#or  and\nSELECT last_name,salary,department_id\nFROM employees\n#where department_id=10 or department_id=20;\n#where department_id=10 and department_id=20;\nWHERE department_id=50 AND salary > 6000;\n\n#not\nSELECT last_name,salary,department_id\nFROM employees\n#where salary not between 6000 and 8000;\n#where commission_pct is not null;\nWHERE NOT commission_pct &lt;=> NULL;\n\n#XOR\uff1a\u8ffd\u6c42\u7684\"\u5f02\"\nSELECT last_name\uff0csalary\uff0cdepartment_id\nFROM employees\nWHERE department_id= 50 XOR salary > 6000;<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>OR\u53ef\u4ee5\u548cAND\u4e00\u8d77\u4f7f\u7528\uff0c\u4f46\u662f\u5728\u4f7f\u7528\u65f6\u8981\u6ce8\u610f\u4e24\u8005\u7684\u4f18\u5148\u7ea7\uff0c\u7531\u4e8eAND\u7684\u4f18\u5148\u7ea7\u9ad8\u4e8eOR\uff0c\u56e0\u6b64\u5148\u5bf9AND\u4e24\u8fb9\u7684\u64cd\u4f5c\u6570\u8fdb\u884c\u64cd\u4f5c\uff0c\u518d\u4e0eOR\u4e2d\u7684\u64cd\u4f5c\u6570\u7ed3\u5408\u3002<\/p>\n<\/blockquote>\n\n\n\n<p><strong>4. \u4f4d\u8fd0\u7b97\u7b26<\/strong><\/p>\n\n\n\n<p>\u4f4d\u8fd0\u7b97\u7b26\u662f\u5728\u4e8c\u8fdb\u5236\u6570\u4e0a\u8fdb\u884c\u8ba1\u7b97\u7684\u8fd0\u7b97\u7b26\u3002\u4f4d\u8fd0\u7b97\u7b26\u4f1a\u5148\u5c06\u64cd\u4f5c\u6570\u53d8\u6210\u4e8c\u8fdb\u5236\u6570\uff0c\u7136\u540e\u8fdb\u884c\u4f4d\u8fd0\u7b97\uff0c \u6700\u540e\u5c06\u8ba1\u7b97\u7ed3\u679c\u4ece\u4e8c\u8fdb\u5236\u53d8\u56de\u5341\u8fdb\u5236\u6570\u3002\u4f60\u5e94\u8be5\u662f\u4f1a\u7684,\u8fd9\u662f\u8ba1\u7ec4\u57fa\u7840\u554a(\u8ba1\u7b97\u673a\u5bfc\u8bba\u4e5f\u6709<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>&nbsp;\u8fd0\u7b97\u7b26<\/td><td>\u4f5c\u7528<\/td><td>\u793a\u4f8b<\/td><\/tr><tr><td>&amp;<\/td><td>\u6309\u4f4d\u4e0e\uff08\u4f4dAND\uff09<\/td><td>SELECT&nbsp; A &amp; B<\/td><\/tr><tr><td>|<\/td><td>\u6309\u4f4d\u6216\uff08\u4f4dOR\uff09<\/td><td>SELECT&nbsp; A | B<\/td><\/tr><tr><td>^<\/td><td>\u6309\u4f4d\u5f02\u6216\uff08\u4f4dXOR\uff09<\/td><td>SELECT&nbsp; A^B<\/td><\/tr><tr><td>~<\/td><td>\u6309\u4f4d\u53d6\u53cd<\/td><td>SELECT ~A<\/td><\/tr><tr><td>&gt;&gt;<\/td><td>\u6309\u4f4d\u53f3\u79fb<\/td><td>SELECT A&gt;&gt;2<\/td><\/tr><tr><td>&lt;&lt;<\/td><td>\u6309\u4f4d\u5de6\u79fb<\/td><td>SELECT B&lt;&lt;2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>5. \u8fd0\u7b97\u7b26\u7684\u4f18\u5148\u7ea7<\/strong><br>&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#1.\u9009\u62e9\u5de5\u8d44\u4e0d\u57285000\u523012000\u7684\u5458\u5de5\u7684\u59d3\u540d\u548c\u5de5\u8d44\nSELECT last_name,salary\nFROM employees\n#where salary not between 5000 and 12000;\nWHERE salary &lt; 5000 OR salary &gt; 12000;\n\n#2.\u9009\u62e9\u572820\u621650\u53f7\u90e8\u95e8\u5de5\u4f5c\u7684\u5458\u5de5\u59d3\u540d\u548c\u90e8\u95e8\u53f7\nSELECT last_name,department_id\nFROM employees\n#where department_id in(20,50);\nWHERE department_id=20 OR department_id=50;\n\n#3.<\/code><\/pre>\n\n\n\n<p>&nbsp;\u8bfe\u540e\u7ec3\u4e60<\/p>\n\n\n\n<p>\u5144\u5f1f\u4eec &nbsp;\u8fd9\u53ea\u662f\u5355\u8868\u7684\u7b80\u5355\u67e5\u8be2 &nbsp;\u591a\u8868\u624d\u662f\u6b63\u7ecf\u5f00\u53d1\u4f1a\u7528\u7684<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#1.\u9009\u62e9\u5de5\u8d44\u4e0d\u57285000\u523012000\u7684\u5458\u5de5\u7684\u59d3\u540d\u548c\u5de5\u8d44\nSELECT last_name,salary\nFROM employees\n#where salary not between 5000 and 12000;\nWHERE salary &lt; 5000 OR salary > 12000;\n\n#2.\u9009\u62e9\u572820\u621650\u53f7\u90e8\u95e8\u5de5\u4f5c\u7684\u5458\u5de5\u59d3\u540d\u548c\u90e8\u95e8\u53f7\nSELECT last_name,department_id\nFROM employees\n#where department_id in (20,50);\nWHERE department_id=20 OR department_id=50;\n\n#3.\u9009\u62e9\u516c\u53f8\u4e2d\u6ca1\u6709\u7ba1\u7406\u8005\u7684\u5458\u5de5\u59d3\u540d\u53cajob_id\nSELECT last_name,job_id,manager_id\nFROM employees\nWHERE manager_id IS NULL;\n\nSELECT last_name,job_id,manager_id\nFROM employees\nWHERE manager_id &lt;=>NULL;\n\n#4.\u9009\u62e9\u516c\u53f8\u4e2d\u6709\u5956\u91d1\u7684\u5458\u5de5\u59d3\u540d\uff0c\u5de5\u8d44\u548c\u5956\u91d1\u7ea7\u522b\nSELECT last_name,salary,commission_pct\nFROM employees\nWHERE commission_pct IS NOT NULL;\n\nSELECT last_name,salary,commission_pct\nFROM employees\nWHERE NOT commission_pct &lt;=> NULL;\n\n#5.\u9009\u62e9\u5458\u5de5\u59d3\u540d\u7684\u7b2c\u4e09\u4e2a\u5b57\u6bcd\u662fa\u7684\u5458\u5de5\u59d3\u540d\nSELECT last_name\nFROM employees\nWHERE last_name LIKE '__a%'\n\n#6.\u9009\u62e9\u59d3\u540d\u4e2d\u6709\u5b57\u6bcda\u548ck\u7684\u5458\u5de5\u59d3\u540d\nSELECT last_name\nFROM employees\nWHERE last_name LIKE '%a%k%' OR last_name LIKE '%k%a%';\n#where last_name like '%a%' and last_name LIKE '%k%';\n\n#7.\u663e\u793a\u51fa\u8868employees\u8868\u4e2dfirst_name\u4ee5'e'\u7ed3\u5c3e\u7684\u5458\u5de5\u4fe1\u606f\nSELECT first_name,last_name\nFROM employees\nWHERE first name LIKE '%e';\n\nSELECT first_name,last_name\nFROM employees\nWHERE first_name REGEXP 'e$';#\u4ee5e\u5f00\u5934\u7684\u5199\u6cd5\uff1a'^e'\n\n#8.\u663e\u793a\u51fa\u8868employees\u90e8\u95e8\u7f16\u53f7\u572880-100\u4e4b\u95f4\u7684\u59d3\u540d\u3001\u5de5\u79cd\nSELECT last_name,job_id\nFROM employees\n#\u65b9\u5f0f1\uff1a\u63a8\u8350\nWHERE department_id BETWEEN 80 AND 100;\n#\u65b9\u5f0f2\uff1a\u63a8\u8350\uff0c\u4e0e\u65b9\u5f0f1\u76f8\u540c\n#where department_id>=80 and department_id &lt;=100;\n#\u65b9\u5f0f3\uff1a\u4ec5\u9002\u7528\u4e8e\u672c\u9898\u7684\u65b9\u5f0f\u3002\n#where department_id in (80,90,100);\n\nSELECT *FROM departments;\n\n#9.\u663e\u793a\u51fa\u8868employees\u7684manager_id\u662f100\uff0c101\uff0c110\u7684\u5458\u5de5\u59d3\u540d\u3001\u5de5\u8d44\u3001\u7ba1\u7406\u8005id\nSELECT last_name,salary,manager_id\nFROM employees\nWHERE manager_id IN (100,101,110);<img loading=\"lazy\" decoding=\"async\" height=\"15\" width=\"15\" src=\"blob:https:\/\/eve2333.top\/635ef62a-4771-437e-8d6f-4266c3972cd8\"><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;\u7b2c04\u7ae0_\u8fd0\u7b97\u7b26 1. \u7b97\u672f\u8fd0\u7b97\u7b26 \u7b97\u672f\u8fd0\u7b97\u7b26\u4e3b\u8981\u7528\u4e8e\u6570\u5b66\u8fd0\u7b97\uff0c\u5176\u53ef\u4ee5\u8fde\u63a5\u8fd0\u7b97\u7b26\u524d\u540e\u7684\u4e24\u4e2a\u6570\u503c\u6216\u8868\u8fbe\u5f0f\uff0c\u5bf9\u6570\u503c\u6216\u8868\u8fbe\u5f0f &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-800","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts\/800","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=800"}],"version-history":[{"count":1,"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts\/800\/revisions"}],"predecessor-version":[{"id":801,"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts\/800\/revisions\/801"}],"wp:attachment":[{"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}