{"id":109,"date":"2025-03-28T13:58:38","date_gmt":"2025-03-28T05:58:38","guid":{"rendered":"https:\/\/zd1269878.noblogs.org\/?p=109"},"modified":"2025-10-21T10:32:15","modified_gmt":"2025-10-21T02:32:15","slug":"2025-03-28-%e6%95%b0%e6%8d%ae%e5%ba%93-%e7%ac%94%e8%ae%b0%e6%95%b4%e7%90%86","status":"publish","type":"post","link":"https:\/\/zd1269878.noblogs.org\/en-US\/post\/2025\/03\/28\/2025-03-28-%e6%95%b0%e6%8d%ae%e5%ba%93-%e7%ac%94%e8%ae%b0%e6%95%b4%e7%90%86\/","title":{"rendered":"2025-03-28-\u6570\u636e\u5e93-\u7b14\u8bb0\u6574\u7406"},"content":{"rendered":"<h2>20250328<\/h2>\n<p>\u4e3b\u952e\u7ea6\u675f \u4e0d\u53ef\u4e3a\u7a7a \u552f\u4e00<\/p>\n<p>\u552f\u4e00\u6027\u7ea6\u675f \u53ef\u4e3a\u7a7a \u552f\u4e00<\/p>\n<p>ADD <strong><em>\u6570\u636e\u5217\u540d<\/em><\/strong> \u6570\u636e\u7c7b\u578b #\u6dfb\u52a0\u65b0\u7684\u5217<\/p>\n<p>DROP <strong><em>COLUMN<\/em><\/strong> \u5217\u540d #\u5220\u9664\u5217<\/p>\n<p>ALTER <strong><em>COLUMN<\/em><\/strong> \u5217\u540d \u65b0\u7684\u6570\u636e\u7c7b\u578b #\u6539\u8be5\u5217\u7684\u6570\u636e\u7c7b\u578b\uff0c\u53ea\u80fd\u52a0\u957f\u4e0d\u80fd\u7f29\u77ed<\/p>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0b\u662f\u5173\u4e8e SQL \u4e2d UPDATE\u3001DELETE \u548c TRUNCATE \u8bed\u53e5\u7684\u4f7f\u7528\u65b9\u6cd5\u53ca\u6ce8\u610f\u4e8b\u9879\u7684\u8be6\u7ec6\u8bf4\u660e\uff1a<\/p>\n<h3><strong>1. UPDATE <\/strong><strong>\u8bed\u53e5<\/strong><\/h3>\n<p><strong>\u7528\u9014<\/strong>\uff1a\u4fee\u6539\u8868\u4e2d\u5df2\u6709\u7684\u6570\u636e\u3002<\/p>\n<h4><strong>\u57fa\u672c\u8bed\u6cd5<\/strong>\uff1a<\/h4>\n<p>UPDATE \u8868\u540d<br \/>\nSET \u52171 = \u503c1, \u52172 = \u503c2, &#8230;<br \/>\nWHERE \u6761\u4ef6;<\/p>\n<h4><strong>\u793a\u4f8b<\/strong>\uff1a<\/h4>\n<p>&#8212; \u5c06\u7528\u6237ID\u4e3a1\u7684\u7528\u6237\u7684\u5e74\u9f84\u66f4\u65b0\u4e3a25<br \/>\nUPDATE users<br \/>\nSET age = 25<br \/>\nWHERE user_id = 1;<\/p>\n<p>&#8212; \u540c\u65f6\u66f4\u65b0\u591a\u4e2a\u5b57\u6bb5<br \/>\nUPDATE employees<br \/>\nSET salary = 50000, department = 'HR'<br \/>\nWHERE employee_id = 101;<\/p>\n<h4><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a<\/h4>\n<ul>\n<li><strong>\u52a1\u5fc5\u4f7f\u7528 <\/strong><strong>WHERE<\/strong> <strong>\u5b50\u53e5<\/strong>\uff1a\u5982\u679c\u7701\u7565 WHERE\uff0c\u8868\u4e2d\u6240\u6709\u884c\u7684\u6307\u5b9a\u5217\u90fd\u4f1a\u88ab\u66f4\u65b0\uff01<\/li>\n<li><strong>\u4e8b\u52a1\u5b89\u5168<\/strong>\uff1a\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u5efa\u8bae\u5728\u66f4\u65b0\u524d\u5f00\u542f\u4e8b\u52a1\uff08\u5982 BEGIN TRANSACTION\uff09\uff0c\u4ee5\u4fbf\u5728\u51fa\u9519\u65f6\u56de\u6eda\u3002<\/li>\n<li><strong>\u5907\u4efd\u6570\u636e<\/strong>\uff1a\u5bf9\u5173\u952e\u6570\u636e\u64cd\u4f5c\u524d\uff0c\u5efa\u8bae\u5148\u5907\u4efd\uff08\u5982 CREATE TABLE users_backup AS SELECT * FROM users\uff09\u3002<\/li>\n<\/ul>\n<h3><strong>2. DELETE <\/strong><strong>\u8bed\u53e5<\/strong><\/h3>\n<p><strong>\u7528\u9014<\/strong>\uff1a\u5220\u9664\u8868\u4e2d\u7684\u6570\u636e\u884c\u3002<\/p>\n<h4><strong>\u57fa\u672c\u8bed\u6cd5<\/strong>\uff1a<\/h4>\n<p>DELETE FROM \u8868\u540d<br \/>\nWHERE \u6761\u4ef6;<\/p>\n<h4><strong>\u793a\u4f8b<\/strong>\uff1a<\/h4>\n<p>&#8212; \u5220\u9664\u7528\u6237ID\u4e3a1\u7684\u8bb0\u5f55<br \/>\nDELETE FROM users<br \/>\nWHERE user_id = 1;<\/p>\n<p>&#8212; \u5220\u9664\u6240\u6709\u5e74\u9f84\u5927\u4e8e60\u7684\u8bb0\u5f55<br \/>\nDELETE FROM employees<br \/>\nWHERE age &gt; 60;<\/p>\n<h4><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a<\/h4>\n<ul>\n<li><strong>WHERE<\/strong> <strong>\u5b50\u53e5\u540c\u6837\u5173\u952e<\/strong>\uff1a\u7701\u7565 WHERE \u4f1a\u5220\u9664\u8868\u4e2d\u6240\u6709\u6570\u636e\uff01<\/li>\n<li><strong>\u6027\u80fd\u95ee\u9898<\/strong>\uff1a\u5220\u9664\u5927\u91cf\u6570\u636e\u65f6\uff0cDELETE \u4f1a\u9010\u884c\u64cd\u4f5c\u5e76\u8bb0\u5f55\u65e5\u5fd7\uff0c\u53ef\u80fd\u8f83\u6162\u3002<\/li>\n<li><strong>\u89e6\u53d1\u5668<\/strong>\uff1aDELETE \u4f1a\u89e6\u53d1 DELETE \u7c7b\u578b\u7684\u89e6\u53d1\u5668\uff08\u5982\u679c\u6709\uff09\u3002<\/li>\n<li><strong>\u4e8b\u52a1\u4e0e\u5907\u4efd<\/strong>\uff1a\u540c UPDATE\uff0c\u5efa\u8bae\u64cd\u4f5c\u524d\u5907\u4efd\u5e76\u4f7f\u7528\u4e8b\u52a1\u3002<\/li>\n<\/ul>\n<h3><strong>3. TRUNCATE <\/strong><strong>\u8bed\u53e5<\/strong><\/h3>\n<p><strong>\u7528\u9014<\/strong>\uff1a\u5feb\u901f\u5220\u9664\u8868\u4e2d\u6240\u6709\u6570\u636e\uff08\u4e0d\u53ef\u9006\u64cd\u4f5c\uff09\u3002<\/p>\n<h4><strong>\u57fa\u672c\u8bed\u6cd5<\/strong>\uff1a<\/h4>\n<p>TRUNCATE TABLE \u8868\u540d;<\/p>\n<h4><strong>\u793a\u4f8b<\/strong>\uff1a<\/h4>\n<p>TRUNCATE TABLE logs;\u00a0 &#8212; \u6e05\u7a7a logs \u8868\u7684\u6240\u6709\u6570\u636e<\/p>\n<h4><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a<\/h4>\n<ul>\n<li><strong>\u4e0d\u53ef\u9006<\/strong>\uff1aTRUNCATE \u4f1a\u76f4\u63a5\u5220\u9664\u6240\u6709\u6570\u636e\uff0c\u4e14<strong>\u65e0\u6cd5\u901a\u8fc7\u4e8b\u52a1\u56de\u6eda<\/strong>\uff08\u9664\u975e\u5728\u652f\u6301\u4e8b\u52a1\u7684\u6570\u636e\u5e93\u4e2d\u663e\u5f0f\u4f7f\u7528 ROLLBACK\uff09\u3002<\/li>\n<li><strong>\u6548\u7387\u9ad8<\/strong>\uff1a\u4e0d\u9010\u884c\u5220\u9664\uff0c\u800c\u662f\u91ca\u653e\u6570\u636e\u9875\uff0c\u65e5\u5fd7\u8bb0\u5f55\u5c11\uff0c\u901f\u5ea6\u8fdc\u5feb\u4e8e DELETE\u3002<\/li>\n<li><strong>\u91cd\u7f6e\u81ea\u589e\u5217<\/strong>\uff1a\u4f1a\u5c06\u81ea\u589e\u5217\uff08\u5982 AUTO_INCREMENT \u6216 IDENTITY\uff09\u91cd\u7f6e\u4e3a\u521d\u59cb\u503c\u3002<\/li>\n<li><strong>\u6743\u9650\u8981\u6c42<\/strong>\uff1a\u901a\u5e38\u9700\u8981\u66f4\u9ad8\u6743\u9650\uff08\u5982 DROP \u6743\u9650\uff09\u3002<\/li>\n<li><strong>\u4e0d\u89e6\u53d1\u89e6\u53d1\u5668<\/strong>\uff1a\u4e0d\u4f1a\u89e6\u53d1 DELETE \u89e6\u53d1\u5668\u3002<\/li>\n<\/ul>\n<h3><strong>DELETE vs TRUNCATE <\/strong><strong>\u5bf9\u6bd4<\/strong><\/h3>\n<table>\n<thead>\n<tr>\n<td>\u7279\u6027<\/td>\n<td>DELETE<\/td>\n<td>TRUNCATE<\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u5220\u9664\u8303\u56f4<\/strong><\/td>\n<td>\u53ef\u4ee5\u6709\u6761\u4ef6\u5220\u9664\u90e8\u5206\u6570\u636e<\/td>\n<td>\u53ea\u80fd\u5220\u9664\u5168\u90e8\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td><strong>\u65e5\u5fd7\u8bb0\u5f55<\/strong><\/td>\n<td>\u9010\u884c\u8bb0\u5f55\u65e5\u5fd7\uff0c\u8f83\u6162<\/td>\n<td>\u6574\u4f53\u91ca\u653e\u6570\u636e\u9875\uff0c\u901f\u5ea6\u5feb<\/td>\n<\/tr>\n<tr>\n<td><strong>\u4e8b\u52a1\u56de\u6eda<\/strong><\/td>\n<td>\u53ef\u56de\u6eda\uff08\u9700\u5728\u4e8b\u52a1\u4e2d\uff09<\/td>\n<td>\u901a\u5e38\u4e0d\u53ef\u56de\u6eda<\/td>\n<\/tr>\n<tr>\n<td><strong>\u81ea\u589e\u5217\u91cd\u7f6e<\/strong><\/td>\n<td>\u4e0d\u91cd\u7f6e\u81ea\u589e\u5217<\/td>\n<td>\u91cd\u7f6e\u81ea\u589e\u5217\u5230\u521d\u59cb\u503c<\/td>\n<\/tr>\n<tr>\n<td><strong>\u89e6\u53d1\u5668<\/strong><\/td>\n<td>\u89e6\u53d1 DELETE \u89e6\u53d1\u5668<\/td>\n<td>\u4e0d\u89e6\u53d1<\/td>\n<\/tr>\n<tr>\n<td><strong>\u8bed\u6cd5\u590d\u6742\u5ea6<\/strong><\/td>\n<td>\u652f\u6301\u590d\u6742\u6761\u4ef6\uff08\u5982\u5b50\u67e5\u8be2\uff09<\/td>\n<td>\u4ec5\u80fd\u6e05\u7a7a\u6574\u4e2a\u8868<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong>\u4f7f\u7528\u5efa\u8bae<\/strong><\/h3>\n<ol>\n<li><strong>\u8c28\u614e\u64cd\u4f5c<\/strong>\uff1a\u5728\u751f\u4ea7\u73af\u5883\u6267\u884c\u524d\uff0c\u5148\u7528 SELECT * FROM \u8868\u540d WHERE \u6761\u4ef6 \u786e\u8ba4\u5f71\u54cd\u8303\u56f4\u3002<\/li>\n<li><strong>\u4f18\u5148\u4f7f\u7528 <\/strong><strong>TRUNCATE<\/strong>\uff1a\u5982\u679c\u9700\u8981\u6e05\u7a7a\u8868\u4e14\u65e0\u9700\u6761\u4ef6\uff0c\u4f18\u5148\u9009\u62e9 TRUNCATE \u4ee5\u63d0\u9ad8\u6548\u7387\u3002<\/li>\n<li><strong>\u907f\u514d\u5168\u8868\u64cd\u4f5c<\/strong>\uff1a\u5bf9\u5927\u8868\u6267\u884c DELETE \u6216 TRUNCATE \u65f6\uff0c\u6ce8\u610f\u9501\u8868\u548c\u6027\u80fd\u95ee\u9898\u3002<\/li>\n<li><strong>\u6743\u9650\u63a7\u5236<\/strong>\uff1a\u4e25\u683c\u9650\u5236\u5bf9 TRUNCATE \u7684\u6743\u9650\uff0c\u9632\u6b62\u8bef\u64cd\u4f5c\u3002<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>DISTINCT\u67e5\u8be2\u65f6\u53bb\u91cd<\/p>\n<p>SELECT DISTINCT FROM WHERE GROUP BY HAVING ORDER BY<\/p>\n<p>\u5728 SQL \u4e2d\uff0cDISTINCT \u5173\u952e\u5b57\u7528\u4e8e\u5728\u67e5\u8be2\u7ed3\u679c\u4e2d\u53bb\u9664\u91cd\u590d\u7684\u884c\u3002\u5f53\u4e0e\u5176\u4ed6\u5b50\u53e5\uff08\u5982 WHERE\u3001GROUP BY\u3001HAVING\u3001ORDER BY\uff09\u7ed3\u5408\u65f6\uff0c\u9700\u6ce8\u610f\u5b83\u4eec\u7684\u6267\u884c\u987a\u5e8f\u548c\u903b\u8f91\u5173\u7cfb\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u7528\u6cd5\u53ca\u793a\u4f8b\uff1a<\/p>\n<h3><strong>1. <\/strong><strong>\u57fa\u672c\u8bed\u6cd5<\/strong><\/h3>\n<p>SELECT DISTINCT column1, column2, &#8230;<br \/>\nFROM table_name<br \/>\nWHERE condition<br \/>\nGROUP BY column1, column2, &#8230;<br \/>\nHAVING group_condition<br \/>\nORDER BY column1 [ASC|DESC], column2 [ASC|DESC];<\/p>\n<h3><strong>2. <\/strong><strong>\u5404\u5b50\u53e5\u4e0e <\/strong><strong>DISTINCT<\/strong> <strong>\u7684\u7ed3\u5408\u4f7f\u7528<\/strong><\/h3>\n<h4><strong>(1) <\/strong><strong>SELECT DISTINCT<\/strong> <strong>\u57fa\u7840\u53bb\u91cd<\/strong><\/h4>\n<ul>\n<li><strong>\u4f5c\u7528<\/strong>\uff1a\u8fd4\u56de\u6307\u5b9a\u5217\u7684\u552f\u4e00\u7ec4\u5408\u503c\u3002<\/li>\n<li><strong>\u793a\u4f8b<\/strong>\uff1a<\/li>\n<\/ul>\n<ul>\n<li>&#8212; \u67e5\u8be2\u4e0d\u91cd\u590d\u7684\u90e8\u95e8\u540d\u79f0<br \/>\nSELECT DISTINCT department<br \/>\nFROM employees;&#8211; \u67e5\u8be2\u90e8\u95e8\u548c\u804c\u4f4d\u7684\u552f\u4e00\u7ec4\u5408<br \/>\nSELECT DISTINCT department, position<br \/>\nFROM employees;<\/li>\n<\/ul>\n<h4><strong>(2) <\/strong><strong>WHERE<\/strong> <strong>\u5b50\u53e5\u8fc7\u6ee4\u540e\u53bb\u91cd<\/strong><\/h4>\n<ul>\n<li><strong>\u6267\u884c\u987a\u5e8f<\/strong>\uff1a\u5148\u6267\u884c WHERE \u8fc7\u6ee4\u6570\u636e\uff0c\u518d\u5bf9\u7ed3\u679c\u53bb\u91cd\u3002<\/li>\n<li><strong>\u793a\u4f8b<\/strong>\uff1a<\/li>\n<\/ul>\n<ul>\n<li>&#8212; \u67e5\u8be2\u5de5\u8d44\u9ad8\u4e8e 5000 \u7684\u5458\u5de5\u6240\u5728\u57ce\u5e02\uff08\u53bb\u91cd\uff09<br \/>\nSELECT DISTINCT city<br \/>\nFROM employees<br \/>\nWHERE salary &gt; 5000;<\/li>\n<\/ul>\n<h4><strong>(3) <\/strong><strong>GROUP BY<\/strong> <strong>\u4e0e <\/strong><strong>DISTINCT<\/strong> <strong>\u7684\u5f02\u540c<\/strong><\/h4>\n<ul>\n<li><strong>\u533a\u522b<\/strong>\uff1a\n<ul>\n<li>DISTINCT \u76f4\u63a5\u53bb\u91cd\uff0c\u8fd4\u56de\u6240\u6709\u5217\u7684\u552f\u4e00\u503c\u3002<\/li>\n<li>GROUP BY \u7528\u4e8e\u5206\u7ec4\u805a\u5408\uff08\u5982 COUNT, SUM\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u793a\u4f8b<\/strong>\uff1a<\/li>\n<\/ul>\n<ul>\n<li>&#8212; \u4f7f\u7528 GROUP BY \u7edf\u8ba1\u6bcf\u4e2a\u90e8\u95e8\u7684\u4eba\u6570\uff08\u65e0\u9700 DISTINCT\uff09<br \/>\nSELECT department, COUNT(*) AS employee_count<br \/>\nFROM employees<br \/>\nGROUP BY department;&#8211; \u82e5\u540c\u65f6\u9700\u8981\u53bb\u91cd\u548c\u5206\u7ec4\uff0c\u9700\u660e\u786e\u903b\u8f91\uff08\u5982\u7edf\u8ba1\u4e0d\u540c\u804c\u4f4d\u7684\u6570\u91cf\uff09<br \/>\nSELECT department, COUNT(DISTINCT position) AS unique_positions<br \/>\nFROM employees<br \/>\nGROUP BY department;<\/li>\n<\/ul>\n<h4><strong>(4) <\/strong><strong>HAVING<\/strong> <strong>\u8fc7\u6ee4\u5206\u7ec4\u540e\u7684\u7ed3\u679c<\/strong><\/h4>\n<ul>\n<li><strong>\u4f5c\u7528<\/strong>\uff1a\u5bf9 GROUP BY \u5206\u7ec4\u540e\u7684\u7ed3\u679c\u8fdb\u884c\u6761\u4ef6\u8fc7\u6ee4\u3002<\/li>\n<li><strong>\u793a\u4f8b<\/strong>\uff1a<\/li>\n<\/ul>\n<ul>\n<li>&#8212; \u67e5\u8be2\u5458\u5de5\u6570\u8d85\u8fc7 5 \u4eba\u7684\u90e8\u95e8\uff08\u9700 GROUP BY\uff09<br \/>\nSELECT department<br \/>\nFROM employees<br \/>\nGROUP BY department<br \/>\nHAVING COUNT(*) &gt; 5;&#8211; \u7ed3\u5408 DISTINCT \u548c HAVING\uff08\u8f83\u5c11\u89c1\uff09<br \/>\nSELECT department, COUNT(DISTINCT city) AS cities<br \/>\nFROM employees<br \/>\nGROUP BY department<br \/>\nHAVING cities &gt; 2;<\/li>\n<\/ul>\n<h4><strong>(5) <\/strong><strong>ORDER BY<\/strong> <strong>\u6392\u5e8f\u53bb\u91cd\u7ed3\u679c<\/strong><\/h4>\n<ul>\n<li><strong>\u4f5c\u7528<\/strong>\uff1a\u5bf9\u6700\u7ec8\u7ed3\u679c\u6309\u6307\u5b9a\u5217\u6392\u5e8f\u3002<\/li>\n<li><strong>\u793a\u4f8b<\/strong>\uff1a<\/li>\n<\/ul>\n<ul>\n<li>&#8212; \u6309\u6ce8\u518c\u65f6\u95f4\u964d\u5e8f\u6392\u5217\u4e0d\u91cd\u590d\u7684\u7528\u6237\u540d<br \/>\nSELECT DISTINCT username<br \/>\nFROM users<br \/>\nORDER BY registration_date DESC;<\/li>\n<\/ul>\n<h3><strong>3. <\/strong><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/h3>\n<ol>\n<li><strong>\u591a\u5217\u53bb\u91cd<\/strong>\uff1aDISTINCT \u4f5c\u7528\u4e8e\u6240\u6709\u5217\u7684\u7ec4\u5408\uff0c\u800c\u975e\u5355\u5217\u3002\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n<ul>\n<li>SELECTDISTINCT department, position FROM employees;<br \/>\n&#8212; \u7ed3\u679c\u4e2d department \u548c position \u7684\u7ec4\u5408\u662f\u552f\u4e00\u7684\u3002<\/li>\n<\/ul>\n<ol>\n<li><strong>\u6027\u80fd\u95ee\u9898<\/strong>\uff1aDISTINCT \u53ef\u80fd\u5bfc\u81f4\u5168\u8868\u626b\u63cf\u548c\u6392\u5e8f\uff0c\u5927\u6570\u636e\u91cf\u65f6\u9700\u8c28\u614e\u4f7f\u7528\u3002<\/li>\n<li><strong>\u907f\u514d\u6df7\u6dc6<\/strong>\uff1a<\/li>\n<\/ol>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li>DISTINCT \u4e0d\u9002\u7528\u4e8e\u805a\u5408\u51fd\u6570\u5185\u90e8\uff08\u4f46 COUNT(DISTINCT column) \u662f\u5408\u6cd5\u7684\uff09\u3002<\/li>\n<li>\u4e0d\u80fd\u540c\u65f6\u4f7f\u7528 DISTINCT \u548c GROUP BY \u5bf9\u540c\u4e00\u5217\u53bb\u91cd\uff08\u903b\u8f91\u51b2\u7a81\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ol>\n<li><strong>\u66ff\u4ee3\u65b9\u6848<\/strong>\uff1a\u82e5\u4ec5\u9700\u53bb\u91cd\uff0c\u4f18\u5148\u7528 DISTINCT\uff1b\u82e5\u9700\u5206\u7ec4\u7edf\u8ba1\uff0c\u4f7f\u7528 GROUP BY\u3002<\/li>\n<\/ol>\n<h3><strong>4. <\/strong><strong>\u5b8c\u6574\u793a\u4f8b<\/strong><\/h3>\n<p>&#8212; \u67e5\u8be2\u5de5\u8d44\u9ad8\u4e8e 5000 \u7684\u5458\u5de5\u6240\u5728\u57ce\u5e02\uff08\u53bb\u91cd\uff09\uff0c\u5e76\u6309\u57ce\u5e02\u540d\u6392\u5e8f<br \/>\nSELECT DISTINCT city<br \/>\nFROM employees<br \/>\nWHERE salary &gt; 5000<br \/>\nORDER BY city;<\/p>\n<p>&#8212; \u7edf\u8ba1\u6bcf\u4e2a\u90e8\u95e8\u7684\u4e0d\u540c\u804c\u4f4d\u6570\u91cf\uff0c\u5e76\u7b5b\u9009\u804c\u4f4d\u6570\u8d85\u8fc7 2 \u7684\u90e8\u95e8<br \/>\nSELECT department, COUNT(DISTINCT position) AS unique_positions<br \/>\nFROM employees<br \/>\nGROUP BY department<br \/>\nHAVING unique_positions &gt; 2;<\/p>\n<p class=\"md-end-block md-p md-focus\"><span class=\"md-plain md-expand\">\u901a\u8fc7\u5408\u7406\u7ec4\u5408\u8fd9\u4e9b\u5b50\u53e5\uff0c\u53ef\u4ee5\u9ad8\u6548\u5b9e\u73b0\u590d\u6742\u7684\u53bb\u91cd\u67e5\u8be2\u9700\u6c42\u3002<\/span><\/p>\n<pre class=\"md-fences md-end-block ty-contain-cm modeLoaded\" lang=\"sql\"><span role=\"presentation\"><span class=\"cm-keyword\">SELECT<\/span> <span class=\"cm-operator\">*<\/span> <span class=\"cm-keyword\">from<\/span> STUDENT t <span class=\"cm-keyword\">where<\/span> ROWNUM<span class=\"cm-operator\">&lt;<\/span><span class=\"cm-number\">0<\/span><span class=\"cm-punctuation\">;<\/span> <span class=\"cm-comment\">#\u6700\u8fd1\u516d\u6761\u8bb0\u5f55<\/span><\/span><\/pre>\n<pre class=\"md-fences md-end-block ty-contain-cm modeLoaded\" lang=\"sql\"><span role=\"presentation\"><span class=\"cm-keyword\">SELECT<\/span> <span class=\"cm-operator\">*<\/span> <span class=\"cm-keyword\">FROM<\/span> STUDENT <span class=\"cm-keyword\">WHERE<\/span> SNAME <span class=\"cm-keyword\">LIKE<\/span> <span class=\"cm-string\">'%\u5f20%'<\/span><span class=\"cm-punctuation\">;<\/span><\/span>\n<span role=\"presentation\"><span class=\"cm-keyword\">SELECT<\/span> <span class=\"cm-operator\">*<\/span> <span class=\"cm-keyword\">FROM<\/span> STUDENT <span class=\"cm-keyword\">WHERE<\/span> SNAME <span class=\"cm-keyword\">LIKE<\/span> <span class=\"cm-string\">'%\u5f20__'<\/span><span class=\"cm-punctuation\">;<\/span> <span class=\"cm-comment\">#\u4e0b\u5212\u7ebf\u4ee3\u8868\u4e00\u4e2a\u5b57\u7b26 \u767e\u5206\u53f7\u4ee3\u8868\u4efb\u610f\u5b57\u7b26<\/span><\/span><\/pre>\n<pre class=\"md-fences md-end-block ty-contain-cm modeLoaded md-focus\" lang=\"sql\"><span role=\"presentation\"><span class=\" CodeMirror-selectedtext\"> \u00a0 \u00a0<\/span><span class=\"cm-keyword CodeMirror-selectedtext\">select<\/span><span class=\"cm-operator CodeMirror-selectedtext\">*<\/span> <span class=\"cm-keyword CodeMirror-selectedtext\">from<\/span><span class=\" CodeMirror-selectedtext\"> STU1 t<\/span><\/span>\n<span role=\"presentation\"><span class=\" CodeMirror-selectedtext\"> \u00a0  oDBCImporter Command Window<\/span><\/span>\n<span role=\"presentation\"><span class=\" CodeMirror-selectedtext\"> \u00a0 \u00a0<\/span><span class=\"cm-keyword CodeMirror-selectedtext\">where<\/span><span class=\" CodeMirror-selectedtext\"> t<\/span><span class=\"cm-variable-2 CodeMirror-selectedtext\">.birthday<\/span> <span class=\"cm-keyword CodeMirror-selectedtext\">between<\/span><span class=\" CodeMirror-selectedtext\"> to_date<\/span><span class=\"cm-bracket CodeMirror-selectedtext\">(<\/span><span class=\"cm-number CodeMirror-selectedtext\">2000<\/span><span class=\"cm-operator CodeMirror-selectedtext\">-<\/span><span class=\"cm-number CodeMirror-selectedtext\">01<\/span><span class=\"cm-operator CodeMirror-selectedtext\">-<\/span><span class=\"cm-number CodeMirror-selectedtext\">01<\/span><span class=\"cm-string CodeMirror-selectedtext\">',yyyy-mm-d'<\/span><span class=\"cm-bracket CodeMirror-selectedtext\">)<\/span> <span class=\"cm-keyword CodeMirror-selectedtext\">and<\/span><span class=\" CodeMirror-selectedtext\"> to_date<\/span><span class=\"cm-bracket CodeMirror-selectedtext\">(<\/span><span class=\"cm-number CodeMirror-selectedtext\">2003<\/span><span class=\" CodeMirror-selectedtext\">\/12\/31<\/span><span class=\"cm-string CodeMirror-selectedtext\">','<\/span><span class=\" CodeMirror-selectedtext\">yyy\/mm\/dd<\/span><span class=\"cm-string CodeMirror-selectedtext\">')<\/span><\/span><\/pre>\n<p>SELECT count(*) from STUDENT;<br \/>\nASC\u4e3a\u5347\u5e8f\uff0cDESC\u4e3a\u964d\u5e8f<br \/>\n'='\u662f\u7cbe\u786e\u5339\u914d\uff0c\u4e0d\u53ef\u7528\u8fc7\u91cf\u901a\u914d\u7b26<br \/>\n'LIKE'\u662f\u6a21\u7cca\u5339\u914d<br \/>\n11-12\u9898<br \/>\n11<br \/>\n(1)ALTER TABLE STUDENT ADD NATION VARCHAR2(20);<br \/>\n(2)ALTER TABLE STUDENT DROP COLUMN NATION;<br \/>\n(3)INSERT INTO GRADE VALUES ('2021110','3','80');<br \/>\n(4)UPDATE GRADE SET GMARK='70' WHERE SNO='2021110';<br \/>\n(5)DELETE FROM GRADE WHERE SNO='2021110';<br \/>\n(6)CREATE INDEX IX_CLASS ON GRADE(CNO ASC);<br \/>\n(7)DROP INDEX IX_CLASS;\/*\u8fd9\u662fORACLE\u7684\u5199\u6cd5*\/<br \/>\n12<br \/>\n(1)SELECT DISTINCT CNO FROM GRADE;<br \/>\n(2)SELECT * FROM STUDENT T WHERE T.SsEX='\u5973' AND T.CLNO='20311';<br \/>\n(3)SELECT T.SNAME,T.SSEX,T.SBIRTH FROM STUDENT T WHERE T.CLNO='20311' OR T.CLNO='20312';<br \/>\n(4)SELECT * FROM STUDENT T WHERE T.SNAME LIKE '\u674e%';<br \/>\n(5)SELECT *<br \/>\n   FROM STUDENT<br \/>\n   WHERE CLNO = (SELECT CLNO FROM STUDENT WHERE SNAME = '\u674e\u52c7');<br \/>\n(6)SELECT<br \/>\n       MAX(GMARK) AS \u6700\u9ad8\u5206,<br \/>\n       MIN(GMARK) AS \u6700\u4f4e\u5206,<br \/>\n       AVG(GMARK) AS \u5e73\u5747\u5206<br \/>\n   FROM GRADE<br \/>\n   WHERE CNO = (SELECT CNO FROM COURSE WHERE CNAME = '\u64cd\u4f5c\u7cfb\u7edf');<br \/>\n(7)SELECT COUNT(DISTINCT SNO)<br \/>\nFROM GRADE;<br \/>\n(8)SELECT COUNT(DISTINCT SNO)<br \/>\nFROM GRADE WHERE CNO=(SELECT CNO FROM COURSE WHERE CNAME='\u64cd\u4f5c\u7cfb\u7edf');<br \/>\n(9)SELECT SNAME<br \/>\nFROM STUDENT<br \/>\nWHERE CLNO IN (<br \/>\n    SELECT CLNO<br \/>\n    FROM CLASS<br \/>\n    WHERE SPECIAL = '\u8f6f\u4ef6\u5de5\u7a0b'<br \/>\n      AND TRIM(INYEAR) = '2020'  &#8212; \u5904\u7406 INYEAR \u662f CHAR(8) \u7684\u7a7a\u683c\u586b\u5145\u95ee\u9898<br \/>\n)<br \/>\n  AND SUBSTR(SNO, 1, 7) NOT IN (  &#8212; \u5339\u914d GRADE.SNO \u7684 CHAR(7) \u957f\u5ea6<br \/>\n    SELECT SNO FROM GRADE<br \/>\n);<br \/>\n\/*\u6b65\u5165\u8ff7\u60d1*\/<br \/>\n(10)<br \/>\nSELECT<br \/>\n    C.CNO,<br \/>\n    C.CNAME,<br \/>\n    C.CPNO AS \u76f4\u63a5\u5148\u4fee\u8bfe\u53f7,<br \/>\n    (SELECT CPNO FROM COURSE WHERE CNO = C.CPNO) AS \u95f4\u63a5\u5148\u4fee\u8bfe\u53f7,<br \/>\n    (SELECT CNAME FROM COURSE<br \/>\n     WHERE CNO = (SELECT CPNO FROM COURSE WHERE CNO = C.CPNO)) AS \u95f4\u63a5\u5148\u4fee\u8bfe\u540d<br \/>\nFROM COURSE C;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>20250328 \u4e3b\u952e\u7ea6\u675f \u4e0d\u53ef\u4e3a\u7a7a \u552f\u4e00 \u552f\u4e00\u6027\u7ea6\u675f \u53ef\u4e3a\u7a7a \u552f\u4e00 ADD \u6570\u636e\u5217\u540d \u6570\u636e\u7c7b\u578b #\u6dfb\u52a0\u65b0\u7684\u5217 DROP COLUMN \u5217\u540d #\u5220\u9664\u5217 ALTER COLUMN \u5217\u540d \u65b0\u7684\u6570\u636e\u7c7b\u578b #\u6539\u8be5\u5217\u7684\u6570\u636e\u7c7b\u578b\uff0c\u53ea\u80fd\u52a0\u957f\u4e0d\u80fd\u7f29\u77ed &nbsp; \u4ee5\u4e0b\u662f\u5173\u4e8e SQL \u4e2d UPDATE\u3001DELETE \u548c TRUNCATE \u8bed\u53e5\u7684\u4f7f\u7528\u65b9\u6cd5\u53ca\u6ce8\u610f\u4e8b\u9879\u7684\u8be6\u7ec6\u8bf4\u660e\uff1a 1. UPDATE \u8bed\u53e5 \u7528\u9014\uff1a\u4fee\u6539\u8868\u4e2d\u5df2\u6709\u7684\u6570\u636e\u3002 \u57fa\u672c\u8bed\u6cd5\uff1a UPDATE \u8868\u540d SET \u52171 = \u503c1, \u52172 = \u503c2, &#8230; WHERE \u6761\u4ef6; \u793a\u4f8b\uff1a &#8212; \u5c06\u7528\u6237ID\u4e3a1\u7684\u7528\u6237\u7684\u5e74\u9f84\u66f4\u65b0\u4e3a25 UPDATE users SET age = 25 WHERE &hellip; <a href=\"https:\/\/zd1269878.noblogs.org\/en-US\/post\/2025\/03\/28\/2025-03-28-%e6%95%b0%e6%8d%ae%e5%ba%93-%e7%ac%94%e8%ae%b0%e6%95%b4%e7%90%86\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">2025-03-28-\u6570\u636e\u5e93-\u7b14\u8bb0\u6574\u7406<\/span><\/a><\/p>\n","protected":false},"author":20615,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/zd1269878.noblogs.org\/?p=109","activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[15],"tags":[16],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-15","tag-16","en-US"],"_links":{"self":[{"href":"https:\/\/zd1269878.noblogs.org\/wp-json\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zd1269878.noblogs.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zd1269878.noblogs.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zd1269878.noblogs.org\/wp-json\/wp\/v2\/users\/20615"}],"replies":[{"embeddable":true,"href":"https:\/\/zd1269878.noblogs.org\/wp-json\/wp\/v2\/comments?post=109"}],"version-history":[{"count":13,"href":"https:\/\/zd1269878.noblogs.org\/wp-json\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":288,"href":"https:\/\/zd1269878.noblogs.org\/wp-json\/wp\/v2\/posts\/109\/revisions\/288"}],"wp:attachment":[{"href":"https:\/\/zd1269878.noblogs.org\/wp-json\/wp\/v2\/media?parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zd1269878.noblogs.org\/wp-json\/wp\/v2\/categories?post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zd1269878.noblogs.org\/wp-json\/wp\/v2\/tags?post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}