{"id":449,"date":"2024-12-22T13:13:20","date_gmt":"2024-12-22T05:13:20","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=449"},"modified":"2024-12-22T13:13:20","modified_gmt":"2024-12-22T05:13:20","slug":"sql-%e6%b1%82%e8%81%8c%e9%9d%a2%e8%af%95%e5%b8%b8%e8%a7%81%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2024\/12\/22\/sql-%e6%b1%82%e8%81%8c%e9%9d%a2%e8%af%95%e5%b8%b8%e8%a7%81%e9%97%ae%e9%a2%98\/","title":{"rendered":"SQL \u6c42\u804c\u9762\u8bd5\u5e38\u89c1\u95ee\u9898"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">SQL \u6c42\u804c\u9762\u8bd5\u5e38\u89c1\u95ee\u9898\u6db5\u76d6\u4e86\u57fa\u7840\u8bed\u6cd5\u3001\u67e5\u8be2\u4f18\u5316\u3001\u6570\u636e\u5e93\u8bbe\u8ba1\u3001\u590d\u6742\u67e5\u8be2\u7b49\u591a\u4e2a\u65b9\u9762\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684 SQL \u9762\u8bd5\u95ee\u9898\u53ca\u5176\u8be6\u7ec6\u89e3\u7b54\uff0c\u5e2e\u52a9\u4f60\u51c6\u5907 SQL \u76f8\u5173\u7684\u6c42\u804c\u9762\u8bd5\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">1. <strong>\u57fa\u7840\u77e5\u8bc6<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.1. <strong>SQL \u4e2d\u7684 <code>PRIMARY KEY<\/code> \u548c <code>FOREIGN KEY<\/code> \u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>PRIMARY KEY<\/strong>\uff1a\u7528\u4e8e\u552f\u4e00\u6807\u8bc6\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u8bb0\u5f55\uff0c\u5177\u6709\u552f\u4e00\u6027\u548c\u975e\u7a7a\u6027\uff08\u4e0d\u80fd\u4e3a NULL\uff09\u3002<\/li>\n\n\n\n<li><strong>FOREIGN KEY<\/strong>\uff1a\u662f\u4e00\u4e2a\u8868\u4e2d\u7684\u5b57\u6bb5\uff0c\u7528\u6765\u5efa\u7acb\u4e0e\u5176\u4ed6\u8868\u7684\u5173\u8054\u5173\u7cfb\uff0c\u5b83\u6307\u5411\u53e6\u4e00\u4e2a\u8868\u7684\u4e3b\u952e\u6216\u552f\u4e00\u952e\u3002\u5916\u952e\u53ef\u4ee5\u4e3a\u7a7a\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">1.2. <strong>\u4ec0\u4e48\u662f <code>NULL<\/code>\uff1f\u5982\u4f55\u5728\u67e5\u8be2\u4e2d\u5904\u7406 <code>NULL<\/code>\uff1f<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>NULL<\/strong>\uff1a\u8868\u793a\u7f3a\u5931\u7684\u6216\u672a\u77e5\u7684\u503c\uff0c\u5e76\u4e0d\u540c\u4e8e\u7a7a\u5b57\u7b26\u4e32\u6216\u96f6\u3002<\/li>\n\n\n\n<li><strong>\u5904\u7406 <code>NULL<\/code><\/strong>\uff1a<\/li>\n\n\n\n<li>\u4f7f\u7528 <code>IS NULL<\/code> \u6216 <code>IS NOT NULL<\/code> \u6765\u68c0\u67e5 <code>NULL<\/code> \u503c\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 <code>COALESCE()<\/code> \u6216 <code>IFNULL()<\/code>\uff08MySQL\uff09\u51fd\u6570\u5c06 <code>NULL<\/code> \u8f6c\u6362\u4e3a\u5176\u4ed6\u503c\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">1.3. <strong>\u4ec0\u4e48\u662f <code>JOIN<\/code>\uff1f\u8bf7\u8bf4\u660e <code>INNER JOIN<\/code>\u3001<code>LEFT JOIN<\/code>\u3001<code>RIGHT JOIN<\/code> \u548c <code>FULL OUTER JOIN<\/code> \u7684\u533a\u522b\u3002<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>INNER JOIN<\/strong>\uff1a\u8fd4\u56de\u4e24\u4e2a\u8868\u4e2d\u5339\u914d\u7684\u8bb0\u5f55\u3002<\/li>\n\n\n\n<li><strong>LEFT JOIN<\/strong>\uff1a\u8fd4\u56de\u5de6\u8868\u7684\u6240\u6709\u8bb0\u5f55\u548c\u53f3\u8868\u7684\u5339\u914d\u8bb0\u5f55\uff0c\u5982\u679c\u53f3\u8868\u6ca1\u6709\u5339\u914d\u5219\u4e3a NULL\u3002<\/li>\n\n\n\n<li><strong>RIGHT JOIN<\/strong>\uff1a\u8fd4\u56de\u53f3\u8868\u7684\u6240\u6709\u8bb0\u5f55\u548c\u5de6\u8868\u7684\u5339\u914d\u8bb0\u5f55\uff0c\u5982\u679c\u5de6\u8868\u6ca1\u6709\u5339\u914d\u5219\u4e3a NULL\u3002<\/li>\n\n\n\n<li><strong>FULL OUTER JOIN<\/strong>\uff1a\u8fd4\u56de\u4e24\u4e2a\u8868\u4e2d\u6240\u6709\u8bb0\u5f55\uff0c\u4e0d\u8bba\u662f\u5426\u5339\u914d\uff0c\u5982\u679c\u6ca1\u6709\u5339\u914d\u5219\u7528 NULL \u586b\u5145\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">1.4. <strong>\u4ec0\u4e48\u662f <code>GROUP BY<\/code> \u548c <code>HAVING<\/code>\uff1f\u5b83\u4eec\u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>GROUP BY<\/strong>\uff1a\u7528\u4e8e\u5c06\u7ed3\u679c\u96c6\u6309\u6307\u5b9a\u7684\u5217\u8fdb\u884c\u5206\u7ec4\u3002<\/li>\n\n\n\n<li><strong>HAVING<\/strong>\uff1a\u7528\u4e8e\u5bf9 <code>GROUP BY<\/code> \u4e4b\u540e\u7684\u7ed3\u679c\u8fdb\u884c\u8fc7\u6ee4\u3002\u4e0e <code>WHERE<\/code> \u4e0d\u540c\uff0c<code>WHERE<\/code> \u7528\u4e8e\u8fc7\u6ee4\u539f\u59cb\u6570\u636e\uff0c\u800c <code>HAVING<\/code> \u7528\u4e8e\u8fc7\u6ee4\u805a\u5408\u7ed3\u679c\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2. <strong>\u67e5\u8be2\u4f18\u5316<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">2.1. <strong>\u5982\u4f55\u4f18\u5316 SQL \u67e5\u8be2\u6027\u80fd\uff1f<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528\u7d22\u5f15<\/strong>\uff1a\u5bf9\u67e5\u8be2\u4e2d\u7ecf\u5e38\u7528\u4e8e\u6761\u4ef6\u7b5b\u9009\u3001\u6392\u5e8f\u7684\u5217\u6dfb\u52a0\u7d22\u5f15\u3002<\/li>\n\n\n\n<li><strong>\u907f\u514d\u4f7f\u7528 <code>SELECT *<\/code><\/strong>\uff1a\u53ea\u9009\u62e9\u9700\u8981\u7684\u5217\uff0c\u51cf\u5c11\u6570\u636e\u91cf\u3002<\/li>\n\n\n\n<li><strong>\u907f\u514d\u5728\u67e5\u8be2\u4e2d\u4f7f\u7528 <code>JOIN<\/code> \u5bf9\u5927\u8868\u8fdb\u884c\u591a\u6b21\u8fde\u63a5<\/strong>\uff1a\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u5b50\u67e5\u8be2\u3001\u4e34\u65f6\u8868\u6216\u5c06\u8868\u62c6\u5206\u6210\u66f4\u5c0f\u7684\u90e8\u5206\u3002<\/li>\n\n\n\n<li><strong>\u5408\u7406\u4f7f\u7528 <code>LIMIT<\/code><\/strong>\uff1a\u9650\u5236\u8fd4\u56de\u7684\u8bb0\u5f55\u6570\uff0c\u5c24\u5176\u662f\u5728\u6570\u636e\u91cf\u975e\u5e38\u5927\u7684\u8868\u4e2d\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528\u67e5\u8be2\u7f13\u5b58<\/strong>\uff1a\u5982\u679c\u6570\u636e\u5e93\u652f\u6301\u67e5\u8be2\u7f13\u5b58\uff0c\u786e\u4fdd\u67e5\u8be2\u7ed3\u679c\u53ef\u4ee5\u7f13\u5b58\uff0c\u4ee5\u51cf\u5c11\u91cd\u590d\u67e5\u8be2\u7684\u5f00\u9500\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2.2. <strong>\u7d22\u5f15\u7684\u79cd\u7c7b\u548c\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5355\u5217\u7d22\u5f15<\/strong>\uff1a\u9488\u5bf9\u5355\u4e2a\u5217\u7684\u7d22\u5f15\u3002<\/li>\n\n\n\n<li><strong>\u8054\u5408\u7d22\u5f15<\/strong>\uff1a\u591a\u4e2a\u5217\u7ec4\u6210\u7684\u590d\u5408\u7d22\u5f15\uff0c\u9002\u7528\u4e8e\u67e5\u8be2\u4e2d\u6d89\u53ca\u591a\u4e2a\u5217\u7684\u60c5\u51b5\u3002<\/li>\n\n\n\n<li><strong>\u552f\u4e00\u7d22\u5f15<\/strong>\uff1a\u4fdd\u8bc1\u7d22\u5f15\u5217\u4e2d\u7684\u503c\u552f\u4e00\uff0c\u907f\u514d\u91cd\u590d\u6570\u636e\u3002<\/li>\n\n\n\n<li><strong>\u5168\u6587\u7d22\u5f15<\/strong>\uff1a\u7528\u4e8e\u6587\u672c\u5217\uff0c\u63d0\u4f9b\u5168\u6587\u641c\u7d22\u529f\u80fd\u3002<\/li>\n\n\n\n<li><strong>\u4e3b\u952e\u7d22\u5f15<\/strong>\uff1a\u4e3b\u952e\u81ea\u52a8\u5efa\u7acb\u7684\u552f\u4e00\u7d22\u5f15\uff0c\u786e\u4fdd\u6570\u636e\u7684\u552f\u4e00\u6027\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3. <strong>\u9ad8\u7ea7\u67e5\u8be2<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">3.1. <strong>\u4ec0\u4e48\u662f\u5b50\u67e5\u8be2\uff1f\u8bf7\u89e3\u91ca\u5173\u8054\u5b50\u67e5\u8be2\u548c\u975e\u5173\u8054\u5b50\u67e5\u8be2\u7684\u533a\u522b\u3002<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b50\u67e5\u8be2<\/strong>\uff1a\u5728\u53e6\u4e00\u4e2a\u67e5\u8be2\u4e2d\u5d4c\u5957\u7684\u67e5\u8be2\u3002<\/li>\n\n\n\n<li><strong>\u5173\u8054\u5b50\u67e5\u8be2<\/strong>\uff1a\u5b50\u67e5\u8be2\u5f15\u7528\u5916\u90e8\u67e5\u8be2\u4e2d\u7684\u5217\u3002\u6bcf\u4e00\u884c\u90fd\u9700\u8981\u91cd\u65b0\u8ba1\u7b97\u5b50\u67e5\u8be2\u3002<\/li>\n\n\n\n<li><strong>\u975e\u5173\u8054\u5b50\u67e5\u8be2<\/strong>\uff1a\u5b50\u67e5\u8be2\u4e0d\u4f9d\u8d56\u5916\u90e8\u67e5\u8be2\uff0c\u53ef\u4ee5\u72ec\u7acb\u8fd0\u884c\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u975e\u5173\u8054\u5b50\u67e5\u8be2<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT name FROM employees WHERE salary &gt; (SELECT AVG(salary) FROM employees);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u5173\u8054\u5b50\u67e5\u8be2<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT name FROM employees e\nWHERE e.salary &gt; (SELECT AVG(salary) FROM employees WHERE department_id = e.department_id);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.2. <strong>\u89e3\u91ca <code>UNION<\/code> \u548c <code>UNION ALL<\/code> \u7684\u533a\u522b\u3002<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>UNION<\/code><\/strong>\uff1a\u8fd4\u56de\u4e24\u4e2a\u67e5\u8be2\u7684\u5e76\u96c6\uff0c\u81ea\u52a8\u53bb\u91cd\u3002<\/li>\n\n\n\n<li><strong><code>UNION ALL<\/code><\/strong>\uff1a\u8fd4\u56de\u4e24\u4e2a\u67e5\u8be2\u7684\u5e76\u96c6\uff0c\u4e0d\u53bb\u91cd\uff0c\u5305\u542b\u6240\u6709\u91cd\u590d\u8bb0\u5f55\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3.3. <strong>\u4ec0\u4e48\u662f\u7a97\u53e3\u51fd\u6570\uff1f\u8bf7\u4e3e\u4f8b\u8bf4\u660e\u5982\u4f55\u4f7f\u7528\u3002<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a97\u53e3\u51fd\u6570\u5141\u8bb8\u4f60\u5728\u7ed3\u679c\u96c6\u7684\u6bcf\u4e00\u884c\u4e0a\u8fdb\u884c\u805a\u5408\u8ba1\u7b97\uff0c\u800c\u4e0d\u9700\u8981\u4f7f\u7528 <code>GROUP BY<\/code>\u3002\u5e38\u7528\u7684\u7a97\u53e3\u51fd\u6570\u5305\u62ec <code>ROW_NUMBER()<\/code>, <code>RANK()<\/code>, <code>DENSE_RANK()<\/code> \u7b49\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u4f7f\u7528 <code>ROW_NUMBER()<\/code><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n    name, \n    salary, \n    ROW_NUMBER() OVER (ORDER BY salary DESC) AS rank\nFROM employees;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4. <strong>\u6570\u636e\u5e93\u8bbe\u8ba1<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">4.1. <strong>\u5982\u4f55\u8bbe\u8ba1\u4e00\u4e2a\u9ad8\u6548\u7684\u6570\u636e\u5e93\uff1f<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u89c4\u8303\u5316<\/strong>\uff1a\u901a\u8fc7\u89c4\u8303\u5316\uff08\u5982 1NF\u30012NF\u30013NF\uff09\u51cf\u5c11\u6570\u636e\u5197\u4f59\uff0c\u63d0\u9ad8\u6570\u636e\u4e00\u81f4\u6027\u3002<\/li>\n\n\n\n<li><strong>\u53cd\u89c4\u8303\u5316<\/strong>\uff1a\u5728\u67e5\u8be2\u6027\u80fd\u9700\u6c42\u8f83\u9ad8\u65f6\uff0c\u9002\u5f53\u8fdb\u884c\u53cd\u89c4\u8303\u5316\uff0c\u51cf\u5c11\u8fde\u63a5\u64cd\u4f5c\u7684\u590d\u6742\u6027\u3002<\/li>\n\n\n\n<li><strong>\u5206\u533a\u548c\u5206\u8868<\/strong>\uff1a\u5bf9\u4e8e\u6570\u636e\u91cf\u975e\u5e38\u5927\u7684\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u5206\u533a\uff08partitioning\uff09\u6216\u5206\u8868\u6280\u672f\u3002<\/li>\n\n\n\n<li><strong>\u5916\u952e\u7ea6\u675f<\/strong>\uff1a\u8bbe\u8ba1\u65f6\u786e\u4fdd\u8868\u95f4\u7684\u5916\u952e\u7ea6\u675f\uff0c\u4fdd\u6301\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002<\/li>\n\n\n\n<li><strong>\u7d22\u5f15\u8bbe\u8ba1<\/strong>\uff1a\u6839\u636e\u67e5\u8be2\u9700\u6c42\u8bbe\u8ba1\u5408\u7406\u7684\u7d22\u5f15\uff0c\u4ee5\u63d0\u9ad8\u68c0\u7d22\u6548\u7387\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4.2. <strong>\u4ec0\u4e48\u662f\u8303\u5f0f\uff1f\u4e3a\u4ec0\u4e48\u8981\u8fdb\u884c\u6570\u636e\u5e93\u89c4\u8303\u5316\uff1f<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8303\u5f0f\u662f\u6570\u636e\u5e93\u8bbe\u8ba1\u4e2d\u7684\u4e00\u7ec4\u89c4\u5219\uff0c\u65e8\u5728\u6d88\u9664\u6570\u636e\u5197\u4f59\uff0c\u907f\u514d\u63d2\u5165\u3001\u66f4\u65b0\u548c\u5220\u9664\u5f02\u5e38\u3002\u5e38\u89c1\u7684\u8303\u5f0f\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7b2c\u4e00\u8303\u5f0f\uff081NF\uff09<\/strong>\uff1a\u786e\u4fdd\u6bcf\u4e2a\u5b57\u6bb5\u90fd\u662f\u539f\u5b50\u7684\uff0c\u5373\u4e0d\u80fd\u6709\u91cd\u590d\u7684\u7ec4\u3002<\/li>\n\n\n\n<li><strong>\u7b2c\u4e8c\u8303\u5f0f\uff082NF\uff09<\/strong>\uff1a\u6ee1\u8db3 1NF\uff0c\u5e76\u4e14\u6d88\u9664\u90e8\u5206\u4f9d\u8d56\uff08\u6bcf\u4e2a\u975e\u4e3b\u952e\u5217\u90fd\u5fc5\u987b\u5b8c\u5168\u4f9d\u8d56\u4e8e\u4e3b\u952e\uff09\u3002<\/li>\n\n\n\n<li><strong>\u7b2c\u4e09\u8303\u5f0f\uff083NF\uff09<\/strong>\uff1a\u6ee1\u8db3 2NF\uff0c\u5e76\u4e14\u6d88\u9664\u4f20\u9012\u4f9d\u8d56\uff08\u975e\u4e3b\u952e\u5217\u4e0d\u4f9d\u8d56\u4e8e\u5176\u4ed6\u975e\u4e3b\u952e\u5217\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">5. <strong>\u5e38\u89c1\u9762\u8bd5\u95ee\u9898\u4e0e\u89e3\u7b54<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">5.1. <strong>\u5982\u4f55\u4ece\u4e00\u4e2a\u8868\u4e2d\u5220\u9664\u91cd\u590d\u8bb0\u5f55\uff1f<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u4f7f\u7528 <code>ROW_NUMBER()<\/code> \u6765\u6807\u8bb0\u91cd\u590d\u8bb0\u5f55\uff0c\u7136\u540e\u5220\u9664\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>WITH CTE AS (\n    SELECT *, ROW_NUMBER() OVER (PARTITION BY column1, column2 ORDER BY id) AS row_num\n    FROM table_name\n)\nDELETE FROM CTE WHERE row_num &gt; 1;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5.2. <strong>\u5982\u4f55\u5728 SQL \u67e5\u8be2\u4e2d\u5904\u7406 NULL \u503c\uff1f<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528 <code>COALESCE()<\/code> \u6216 <code>IFNULL()<\/code> \u5c06 <code>NULL<\/code> \u8f6c\u6362\u4e3a\u5176\u4ed6\u503c\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 <code>IS NULL<\/code> \u6216 <code>IS NOT NULL<\/code> \u68c0\u67e5 <code>NULL<\/code> \u503c\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 <code>NULLIF()<\/code> \u51fd\u6570\u8fd4\u56de <code>NULL<\/code> \u5f53\u4e24\u4e2a\u503c\u76f8\u7b49\u65f6\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">5.3. <strong>\u5982\u4f55\u67e5\u8be2\u67d0\u4e2a\u5b57\u6bb5\u7684\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\uff1f<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT MAX(salary) AS max_salary, MIN(salary) AS min_salary FROM employees;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">6. <strong>\u5e38\u89c1 SQL \u9762\u8bd5\u9898\u603b\u7ed3<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">6.1. <strong>\u67e5\u8be2\u4e00\u4e2a\u8868\u7684\u6240\u6709\u8bb0\u5f55\u7684\u603b\u6570\u3002<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT COUNT(*) FROM table_name;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6.2. <strong>\u67e5\u8be2\u67d0\u4e2a\u8868\u4e2d\u4e0d\u91cd\u590d\u7684\u8bb0\u5f55\u3002<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT DISTINCT column_name FROM table_name;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6.3. <strong>\u67e5\u8be2\u6700\u5927\u548c\u7b2c\u4e8c\u5927\u7684\u5de5\u8d44\u3002<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT MAX(salary) FROM employees WHERE salary &lt; (SELECT MAX(salary) FROM employees);<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3\uff1a<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">SQL \u9762\u8bd5\u901a\u5e38\u6db5\u76d6\u4e86\u4ece\u57fa\u7840\u67e5\u8be2\u5230\u590d\u6742\u67e5\u8be2\u3001\u4f18\u5316\u6280\u5de7\u3001\u6570\u636e\u5e93\u8bbe\u8ba1\u7b49\u591a\u4e2a\u65b9\u9762\uff0c\u51c6\u5907\u65f6\u9700\u8981\u638c\u63e1\u5e38\u89c1\u7684 SQL \u8bed\u6cd5\u3001\u67e5\u8be2\u6280\u5de7\u548c\u4f18\u5316\u65b9\u6cd5\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u591a\u505a\u7ec3\u4e60\u3001\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\u6765\u52a0\u6df1\u5bf9 SQL \u7684\u7406\u89e3\uff0c\u5e76\u719f\u6089\u9762\u8bd5\u4e2d\u53ef\u80fd\u9047\u5230\u7684\u95ee\u9898\u3002\u5e0c\u671b\u8fd9\u4e9b\u89e3\u7b54\u80fd\u5e2e\u52a9\u4f60\u5728\u6c42\u804c\u9762\u8bd5\u4e2d\u53d6\u5f97\u6210\u529f\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL \u6c42\u804c\u9762\u8bd5\u5e38\u89c1\u95ee\u9898\u6db5\u76d6\u4e86\u57fa\u7840\u8bed\u6cd5\u3001\u67e5\u8be2\u4f18\u5316\u3001\u6570\u636e\u5e93\u8bbe\u8ba1\u3001\u590d\u6742\u67e5\u8be2\u7b49\u591a\u4e2a\u65b9\u9762\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684 SQL \u9762 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-449","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=449"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/449\/revisions"}],"predecessor-version":[{"id":450,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/449\/revisions\/450"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}