{"id":878,"date":"2025-02-18T19:42:44","date_gmt":"2025-02-18T11:42:44","guid":{"rendered":"https:\/\/eve2333.top\/?p=878"},"modified":"2025-02-18T19:42:44","modified_gmt":"2025-02-18T11:42:44","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-p-14","status":"publish","type":"post","link":"https:\/\/eve2333.top\/?p=878","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 18"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\u7b2c18\u7ae0_MySQL8\u5176\u5b83\u65b0\u7279\u6027<\/h1>\n\n\n\n<p>\u6bd4\u5982\u7f16\u7801\u8bbe\u8ba1\u57288.0\u540e\u76f4\u63a5\u9ed8\u8ba4utf8mb4\uff0c\u89e3\u51b3\u7f16\u7801\u95ee\u9898\uff1b\u8fd8\u6709\u767b\u5f55\u52a0\u5bc6\u65b9\u5f0f\u7684\u6dfb\u52a0<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. MySQL8\u65b0\u7279\u6027\u6982\u8ff0<\/h2>\n\n\n\n<p>1. \u66f4\u7b80\u4fbf\u7684NoSQL\u652f\u6301 NoSQL\u6cdb\u6307\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93\u548c\u6570\u636e\u5b58\u50a8\u3002\u968f\u7740\u4e92\u8054\u7f51\u5e73\u53f0\u7684\u89c4\u6a21\u98de\u901f\u53d1\u5c55\uff0c\u4f20\u7edf \u7684\u5173\u7cfb\u578b\u6570\u636e\u5e93\u5df2\u7ecf\u8d8a\u6765\u8d8a\u4e0d\u80fd\u6ee1\u8db3\u9700\u6c42\u3002\u4ece5.6\u7248\u672c\u5f00\u59cb\uff0cMySQL\u5c31\u5f00\u59cb\u652f\u6301\u7b80\u5355\u7684NoSQL\u5b58\u50a8\u529f\u80fd\u3002 MySQL 8\u5bf9\u8fd9\u4e00\u529f\u80fd\u505a\u4e86\u4f18\u5316\uff0c\u4ee5\u66f4\u7075\u6d3b\u7684\u65b9\u5f0f\u5b9e\u73b0NoSQL\u529f\u80fd\uff0c\u4e0d\u518d\u4f9d\u8d56\u6a21\u5f0f\uff08schema\uff09\u3002<\/p>\n\n\n\n<p>2. \u66f4\u597d\u7684\u7d22\u5f15 \u5728\u67e5\u8be2\u4e2d\uff0c\u6b63\u786e\u5730\u4f7f\u7528\u7d22\u5f15\u53ef\u4ee5\u63d0\u9ad8\u67e5\u8be2\u7684\u6548\u7387\u3002MySQL 8\u4e2d\u65b0\u589e\u4e86 \u9690\u85cf\u7d22\u5f15\u548c \u964d\u5e8f\u7d22 \u5f15\u3002\u9690\u85cf\u7d22\u5f15\u53ef\u4ee5\u7528\u6765\u6d4b\u8bd5\u53bb\u6389\u7d22\u5f15\u5bf9\u67e5\u8be2\u6027\u80fd\u7684\u5f71\u54cd\u3002\u5728\u67e5\u8be2\u4e2d\u6df7\u5408\u5b58\u5728\u591a\u5217\u7d22\u5f15\u65f6\uff0c\u4f7f\u7528\u964d\u5e8f\u7d22\u5f15 \u53ef\u4ee5\u63d0\u9ad8\u67e5\u8be2\u7684\u6027\u80fd\u3002<\/p>\n\n\n\n<p>3.\u66f4\u5b8c\u5584\u7684JSON\u652f\u6301 MySQL\u4ece5.7\u5f00\u59cb\u652f\u6301\u539f\u751fJSON\u6570\u636e\u7684\u5b58\u50a8\uff0cMySQL 8\u5bf9\u8fd9\u4e00\u529f\u80fd\u505a\u4e86\u4f18\u5316\uff0c\u589e\u52a0 \u4e86\u805a\u5408\u51fd\u6570 JSON_ARRAYAGG() \u548c JSON_OBJECTAGG() \uff0c\u5c06\u53c2\u6570\u805a\u5408\u4e3aJSON\u6570\u7ec4\u6216\u5bf9\u8c61\uff0c\u65b0\u589e\u4e86\u884c\u5185 \u64cd\u4f5c\u7b26 -&gt;&gt;\uff0c\u662f\u5217\u8def\u5f84\u8fd0\u7b97\u7b26 -&gt;\u7684\u589e\u5f3a\uff0c\u5bf9JSON\u6392\u5e8f\u505a\u4e86\u63d0\u5347\uff0c\u5e76\u4f18\u5316\u4e86JSON\u7684\u66f4\u65b0\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>4.\u5b89\u5168\u548c\u8d26\u6237\u7ba1\u7406 MySQL 8\u4e2d\u65b0\u589e\u4e86 caching_sha2_password \u6388\u6743\u63d2\u4ef6\u3001\u89d2\u8272\u3001\u5bc6\u7801\u5386\u53f2\u8bb0\u5f55\u548cFIPS \u6a21\u5f0f\u652f\u6301\uff0c\u8fd9\u4e9b\u7279\u6027\u63d0\u9ad8\u4e86\u6570\u636e\u5e93\u7684\u5b89\u5168\u6027\u548c\u6027\u80fd\uff0c\u4f7f\u6570\u636e\u5e93\u7ba1\u7406\u5458\u80fd\u591f\u66f4\u7075\u6d3b\u5730\u8fdb\u884c\u8d26\u6237\u7ba1\u7406\u5de5\u4f5c\u3002<\/p>\n\n\n\n<p>5.InnoDB\u7684\u53d8\u5316 InnoDB\u662fMySQL\u9ed8\u8ba4\u7684\u5b58\u50a8\u5f15\u64ce \uff0c\u662f\u4e8b\u52a1\u578b\u6570\u636e\u5e93\u7684\u9996\u9009\u5f15\u64ce\uff0c\u652f\u6301\u4e8b\u52a1\u5b89\u5168\u8868 \uff08ACID\uff09\uff0c\u652f\u6301\u884c\u9501\u5b9a\u548c\u5916\u952e\u3002\u5728MySQL 8 \u7248\u672c\u4e2d\uff0cInnoDB\u5728\u81ea\u589e\u3001\u7d22\u5f15\u3001\u52a0\u5bc6\u3001\u6b7b\u9501\u3001\u5171\u4eab\u9501\u7b49\u65b9\u9762 \u505a\u4e86\u5927\u91cf\u7684 \u6539\u8fdb\u548c\u4f18\u5316\uff0c\u5e76\u4e14\u652f\u6301\u539f\u5b50\u6570\u636e\u5b9a\u4e49\u8bed\u8a00\uff08DDL\uff09\uff0c\u63d0\u9ad8\u4e86\u6570\u636e\u5b89\u5168\u6027\uff0c\u5bf9\u4e8b\u52a1\u63d0\u4f9b\u66f4\u597d\u7684 \u652f\u6301\u3002<\/p>\n\n\n\n<p>6.\u6570\u636e\u5b57\u5178 \u5728\u4e4b\u524d\u7684MySQL\u7248\u672c\u4e2d\uff0c\u5b57\u5178\u6570\u636e\u90fd\u5b58\u50a8\u5728\u5143\u6570\u636e\u6587\u4ef6\u548c\u975e\u4e8b\u52a1\u8868\u4e2d\u3002\u4eceMySQL 8\u5f00\u59cb\u65b0\u589e \u4e86\u4e8b\u52a1\u6570\u636e\u5b57\u5178\uff0c\u5728\u8fd9\u4e2a\u5b57\u5178\u91cc\u5b58\u50a8\u7740\u6570\u636e\u5e93\u5bf9\u8c61\u4fe1\u606f\uff0c\u8fd9\u4e9b\u6570\u636e\u5b57\u5178\u5b58\u50a8\u5728\u5185\u90e8\u4e8b\u52a1\u8868\u4e2d\u3002<\/p>\n\n\n\n<p>7. \u539f\u5b50\u6570\u636e\u5b9a\u4e49\u8bed\u53e5 MySQL 8\u5f00\u59cb\u652f\u6301\u539f\u5b50\u6570\u636e\u5b9a\u4e49\u8bed\u53e5\uff08Automic DDL\uff09\uff0c\u5373 \u539f\u5b50DDL \u3002\u76ee\u524d\uff0c\u53ea\u6709 InnoDB\u5b58\u50a8\u5f15\u64ce\u652f\u6301\u539f\u5b50DDL\u3002\u539f\u5b50\u6570\u636e\u5b9a\u4e49\u8bed\u53e5\uff08DDL\uff09\u5c06\u4e0eDDL\u64cd\u4f5c\u76f8\u5173\u7684\u6570\u636e\u5b57\u5178\u66f4\u65b0\u3001\u5b58\u50a8\u5f15\u64ce \u64cd\u4f5c\u3001\u4e8c\u8fdb\u5236\u65e5\u5fd7\u5199\u5165\u7ed3\u5408\u5230\u4e00\u4e2a\u5355\u72ec\u7684\u539f\u5b50\u4e8b\u52a1\u4e2d\uff0c\u8fd9\u4f7f\u5f97\u5373\u4f7f\u670d\u52a1\u5668\u5d29\u6e83\uff0c\u4e8b\u52a1\u4e5f\u4f1a\u63d0\u4ea4\u6216\u56de\u6eda\u3002 \u4f7f\u7528\u652f\u6301\u539f\u5b50\u64cd\u4f5c\u7684\u5b58\u50a8\u5f15\u64ce\u6240\u521b\u5efa\u7684\u8868\uff0c\u5728\u6267\u884cDROP TABLE\u3001CREATE TABLE\u3001ALTER TABLE\u3001 RENAME TABLE\u3001TRUNCATE TABLE\u3001CREATE TABLESPACE\u3001DROP TABLESPACE\u7b49\u64cd\u4f5c\u65f6\uff0c\u90fd\u652f\u6301\u539f\u5b50\u64cd \u4f5c\uff0c\u5373\u4e8b\u52a1\u8981\u4e48\u5b8c\u5168\u64cd\u4f5c\u6210\u529f\uff0c\u8981\u4e48\u5931\u8d25\u540e\u56de\u6eda\uff0c\u4e0d\u518d\u8fdb\u884c\u90e8\u5206\u63d0\u4ea4\u3002 \u5bf9\u4e8e\u4eceMySQL 5.7\u590d\u5236\u5230MySQL 8 \u7248\u672c\u4e2d\u7684\u8bed\u53e5\uff0c\u53ef\u4ee5\u6dfb\u52a0 IF EXISTS \u6216 IF NOT EXISTS \u8bed\u53e5\u6765\u907f\u514d\u53d1\u751f\u9519\u8bef\u3002<\/p>\n\n\n\n<p>8.\u8d44\u6e90\u7ba1\u7406 MySQL 8\u5f00\u59cb\u652f\u6301\u521b\u5efa\u548c\u7ba1\u7406\u8d44\u6e90\u7ec4\uff0c\u5141\u8bb8\u5c06\u670d\u52a1\u5668\u5185\u8fd0\u884c\u7684\u7ebf\u7a0b\u5206\u914d\u7ed9\u7279\u5b9a\u7684\u5206\u7ec4\uff0c\u4ee5\u4fbf \u7ebf\u7a0b\u6839\u636e\u7ec4\u5185\u53ef\u7528\u8d44\u6e90\u6267\u884c\u3002\u7ec4\u5c5e\u6027\u80fd\u591f\u63a7\u5236\u7ec4\u5185\u8d44\u6e90\uff0c\u542f\u7528\u6216\u9650\u5236\u7ec4\u5185\u8d44\u6e90\u6d88\u8017\u3002\u6570\u636e\u5e93\u7ba1\u7406\u5458\u80fd\u591f \u6839\u636e\u4e0d\u540c\u7684\u5de5\u4f5c\u8d1f\u8f7d\u9002\u5f53\u5730\u66f4\u6539\u8fd9\u4e9b\u5c5e\u6027\u3002 \u76ee\u524d\uff0cCPU\u65f6\u95f4\u662f\u53ef\u63a7\u8d44\u6e90\uff0c\u7531\u201c\u865a\u62dfCPU\u201d\u8fd9\u4e2a\u6982\u5ff5\u6765\u8868 \u793a\uff0c\u6b64\u672f\u8bed\u5305\u542bCPU\u7684\u6838\u5fc3\u6570\uff0c\u8d85\u7ebf\u7a0b\uff0c\u786c\u4ef6\u7ebf\u7a0b\u7b49\u7b49\u3002\u670d\u52a1\u5668\u5728\u542f\u52a8\u65f6\u786e\u5b9a\u53ef\u7528\u7684\u865a\u62dfCPU\u6570\u91cf\u3002\u62e5\u6709 \u5bf9\u5e94\u6743\u9650\u7684\u6570\u636e\u5e93\u7ba1\u7406\u5458\u53ef\u4ee5\u5c06\u8fd9\u4e9bCPU\u4e0e\u8d44\u6e90\u7ec4\u5173\u8054\uff0c\u5e76\u4e3a\u8d44\u6e90\u7ec4\u5206\u914d\u7ebf\u7a0b\u3002 \u8d44\u6e90\u7ec4\u7ec4\u4ef6\u4e3aMySQL\u4e2d \u7684\u8d44\u6e90\u7ec4\u7ba1\u7406\u63d0\u4f9b\u4e86SQL\u63a5\u53e3\u3002\u8d44\u6e90\u7ec4\u7684\u5c5e\u6027\u7528\u4e8e\u5b9a\u4e49\u8d44\u6e90\u7ec4\u3002MySQL\u4e2d\u5b58\u5728\u4e24\u4e2a\u9ed8\u8ba4\u7ec4\uff0c\u7cfb\u7edf\u7ec4\u548c\u7528\u6237 \u7ec4\uff0c\u9ed8\u8ba4\u7684\u7ec4\u4e0d\u80fd\u88ab\u5220\u9664\uff0c\u5176\u5c5e\u6027\u4e5f\u4e0d\u80fd\u88ab\u66f4\u6539\u3002\u5bf9\u4e8e\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u7ec4\uff0c\u8d44\u6e90\u7ec4\u521b\u5efa\u65f6\u53ef\u521d\u59cb\u5316\u6240\u6709\u7684 \u5c5e\u6027\uff0c\u9664\u53bb\u540d\u5b57\u548c\u7c7b\u578b\uff0c\u5176\u4ed6\u5c5e\u6027\u90fd\u53ef\u5728\u521b\u5efa\u4e4b\u540e\u8fdb\u884c\u66f4\u6539\u3002 \u5728\u4e00\u4e9b\u5e73\u53f0\u4e0b\uff0c\u6216\u8fdb\u884c\u4e86\u67d0\u4e9bMySQL\u7684\u914d \u7f6e\u65f6\uff0c\u8d44\u6e90\u7ba1\u7406\u7684\u529f\u80fd\u5c06\u53d7\u5230\u9650\u5236\uff0c\u751a\u81f3\u4e0d\u53ef\u7528\u3002\u4f8b\u5982\uff0c\u5982\u679c\u5b89\u88c5\u4e86\u7ebf\u7a0b\u6c60\u63d2\u4ef6\uff0c\u6216\u8005\u4f7f\u7528\u7684\u662fmacOS \u7cfb\u7edf\uff0c\u8d44\u6e90\u7ba1\u7406\u5c06\u5904\u4e8e\u4e0d\u53ef\u7528\u72b6\u6001\u3002\u5728FreeBSD\u548cSolaris\u7cfb\u7edf\u4e2d\uff0c\u8d44\u6e90\u7ebf\u7a0b\u4f18\u5148\u7ea7\u5c06\u5931\u6548\u3002\u5728Linux\u7cfb\u7edf \u4e2d\uff0c\u53ea\u6709\u914d\u7f6e\u4e86CAP_SYS_NICE\u5c5e\u6027\uff0c\u8d44\u6e90\u7ba1\u7406\u4f18\u5148\u7ea7\u624d\u80fd\u53d1\u6325\u4f5c\u7528\u3002<\/p>\n\n\n\n<p>9.\u5b57\u7b26\u96c6\u652f\u6301 MySQL 8\u4e2d\u9ed8\u8ba4\u7684\u5b57\u7b26\u96c6\u7531 latin1 \u66f4\u6539\u4e3a \u5408\uff0cutf8mb4_ja_0900_as_cs\u3002 utf8mb4 \uff0c\u5e76\u9996\u6b21\u589e\u52a0\u4e86\u65e5\u8bed\u6240\u7279\u5b9a\u4f7f\u7528\u7684\u96c6<\/p>\n\n\n\n<p>10.\u4f18\u5316\u5668\u589e\u5f3a MySQL\u4f18\u5316\u5668\u5f00\u59cb\u652f\u6301\u9690\u85cf\u7d22\u5f15\u548c\u964d\u5e8f\u7d22\u5f15\u3002\u9690\u85cf\u7d22\u5f15\u4e0d\u4f1a\u88ab\u4f18\u5316\u5668\u4f7f\u7528\uff0c\u9a8c\u8bc1\u7d22\u5f15\u7684\u5fc5 \u8981\u6027\u65f6\u4e0d\u9700\u8981\u5220\u9664\u7d22\u5f15\uff0c\u5148\u5c06\u7d22\u5f15\u9690\u85cf\uff0c\u5982\u679c\u4f18\u5316\u5668\u6027\u80fd\u65e0\u5f71\u54cd\u5c31\u53ef\u4ee5\u771f\u6b63\u5730\u5220\u9664\u7d22\u5f15\u3002\u964d\u5e8f\u7d22\u5f15\u5141\u8bb8 \u4f18\u5316\u5668\u5bf9\u591a\u4e2a\u5217\u8fdb\u884c\u6392\u5e8f\uff0c\u5e76\u4e14\u5141\u8bb8\u6392\u5e8f\u987a\u5e8f\u4e0d\u4e00\u81f4\u3002<\/p>\n\n\n\n<p>11.\u516c\u7528\u8868\u8868\u8fbe\u5f0f \u516c\u7528\u8868\u8868\u8fbe\u5f0f\uff08Common Table Expressions\uff09\u7b80\u79f0\u4e3aCTE\uff0cMySQL\u73b0\u5728\u652f\u6301\u9012\u5f52\u548c\u975e\u9012 \u5f52\u4e24\u79cd\u5f62\u5f0f\u7684CTE\u3002CTE\u901a\u8fc7\u5728SELECT\u8bed\u53e5\u6216\u5176\u4ed6\u7279\u5b9a\u8bed\u53e5\u524d \u4f7f\u7528WITH\u8bed\u53e5\u5bf9\u4e34\u65f6\u7ed3\u679c\u96c6\u8fdb\u884c\u547d\u540d\u3002 \u57fa\u7840\u8bed\u6cd5\u5982\u4e0b\uff1a WITH cte_name (col_name1,col_name2 ...) AS (Subquery) SELECT * FROM cte_name; Subquery\u4ee3\u8868\u5b50\u67e5\u8be2\uff0c\u5b50\u67e5\u8be2\u524d\u4f7f\u7528WITH\u8bed\u53e5\u5c06\u7ed3\u679c\u96c6\u547d\u540d\u4e3acte_name\uff0c\u5728\u540e\u7eed\u7684\u67e5\u8be2\u4e2d\u5373\u53ef\u4f7f\u7528 cte_name\u8fdb\u884c\u67e5\u8be2\u3002<\/p>\n\n\n\n<p>12.\u7a97\u53e3\u51fd\u6570 MySQL 8\u5f00\u59cb\u652f\u6301\u7a97\u53e3\u51fd\u6570\u3002\u5728\u4e4b\u524d\u7684\u7248\u672c\u4e2d\u5df2\u5b58\u5728\u7684\u5927\u90e8\u5206 \u805a\u5408\u51fd\u6570\u5728MySQL 8\u4e2d\u4e5f\u53ef\u4ee5 \u4f5c\u4e3a\u7a97\u53e3\u51fd\u6570\u6765\u4f7f\u7528\u3002<img loading=\"lazy\" decoding=\"async\" height=\"374\" width=\"890\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/50b1a863ca8b4ad59139bbe2bd3dcce0.png\" alt=\"\"><\/p>\n\n\n\n<p>13.\u6b63\u5219\u8868\u8fbe\u5f0f\u652f\u6301 MySQL\u57288.0.4\u4ee5\u540e\u7684\u7248\u672c\u4e2d\u91c7\u7528\u652f\u6301Unicode\u7684\u56fd\u9645\u5316\u7ec4\u4ef6\u5e93\u5b9e\u73b0\u6b63\u5219\u8868\u8fbe\u5f0f\u64cd\u4f5c\uff0c \u8fd9\u79cd\u65b9\u5f0f\u4e0d\u4ec5\u80fd\u63d0\u4f9b\u5b8c\u5168\u7684Unicode\u652f\u6301\uff0c\u800c\u4e14\u662f\u591a\u5b57\u8282\u5b89\u5168\u7f16\u7801\u3002MySQL\u589e\u52a0\u4e86REGEXP_LIKE()\u3001 EGEXP_INSTR()\u3001REGEXP_REPLACE()\u548c REGEXP_SUBSTR()\u7b49\u51fd\u6570\u6765\u63d0\u5347\u6027\u80fd\u3002\u53e6\u5916\uff0cregexp_stack_limit\u548c regexp_time_limit \u7cfb\u7edf\u53d8\u91cf\u80fd\u591f\u901a\u8fc7\u5339\u914d\u5f15\u64ce\u6765\u63a7\u5236\u8d44\u6e90\u6d88\u8017\u3002<\/p>\n\n\n\n<p>14.\u5185\u90e8\u4e34\u65f6\u8868 TempTable\u5b58\u50a8\u5f15\u64ce\u53d6\u4ee3MEMORY\u5b58\u50a8\u5f15\u64ce\u6210\u4e3a\u5185\u90e8\u4e34\u65f6\u8868\u7684\u9ed8\u8ba4\u5b58\u50a8\u5f15\u64ce\u3002TempTable\u5b58\u50a8 \u5f15\u64ce\u4e3aVARCHAR\u548cVARBINARY\u5217\u63d0\u4f9b\u9ad8\u6548\u5b58\u50a8\u3002internal_tmp_mem_storage_engine\u4f1a\u8bdd\u53d8\u91cf\u5b9a\u4e49\u4e86\u5185\u90e8 \u4e34\u65f6\u8868\u7684\u5b58\u50a8\u5f15\u64ce\uff0c\u53ef\u9009\u7684\u503c\u6709\u4e24\u4e2a\uff0cTempTable\u548cMEMORY\uff0c\u5176\u4e2dTempTable\u4e3a\u9ed8\u8ba4\u7684\u5b58\u50a8\u5f15\u64ce\u3002 temptable_max_ram\u7cfb\u7edf\u914d\u7f6e\u9879\u5b9a\u4e49\u4e86TempTable\u5b58\u50a8\u5f15\u64ce\u53ef\u4f7f\u7528\u7684\u6700\u5927\u5185\u5b58\u6570\u91cf\u3002<\/p>\n\n\n\n<p>15.\u65e5\u5fd7\u8bb0\u5f55 \u5728MySQL 8\u4e2d\u9519\u8bef\u65e5\u5fd7\u5b50\u7cfb\u7edf\u7531\u4e00\u7cfb\u5217MySQL\u7ec4\u4ef6\u6784\u6210\u3002\u8fd9\u4e9b\u7ec4\u4ef6\u7684\u6784\u6210\u7531\u7cfb\u7edf\u53d8\u91cf log_error_services\u6765\u914d\u7f6e\uff0c\u80fd\u591f\u5b9e\u73b0\u65e5\u5fd7\u4e8b\u4ef6\u7684\u8fc7\u6ee4\u548c\u5199\u5165\u3002<\/p>\n\n\n\n<p>16.\u5907\u4efd\u9501 \u65b0\u7684\u5907\u4efd\u9501\u5141\u8bb8\u5728\u7ebf\u5907\u4efd\u671f\u95f4\u6267\u884c\u6570\u636e\u64cd\u4f5c\u8bed\u53e5\uff0c\u540c\u65f6\u963b\u6b62\u53ef\u80fd\u9020\u6210\u5feb\u7167\u4e0d\u4e00\u81f4\u7684\u64cd\u4f5c\u3002\u65b0 \u5907\u4efd\u9501\u7531 LOCK INSTANCE FOR BACKUP \u548c UNLOCK INSTANCE \u8bed\u6cd5\u63d0\u4f9b\u652f\u6301\uff0c\u6267\u884c\u8fd9\u4e9b\u64cd\u4f5c\u9700\u8981\u5907\u4efd\u7ba1\u7406 \u5458\u7279\u6743\u3002<\/p>\n\n\n\n<p>17.\u589e\u5f3a\u7684MySQL\u590d\u5236 MySQL 8\u590d\u5236\u652f\u6301\u5bf9 JSON\u6587\u6863 \u8fdb\u884c\u90e8\u5206\u66f4\u65b0\u7684 \u4e8c\u8fdb\u5236\u65e5\u5fd7\u8bb0\u5f55\uff0c\u8be5\u8bb0\u5f55 \u4f7f\u7528\u7d27\u51d1 \u7684\u4e8c\u8fdb\u5236\u683c\u5f0f\uff0c\u4ece\u800c\u8282\u7701\u8bb0\u5f55\u5b8c\u6574JSON\u6587\u6863\u7684\u7a7a\u95f4\u3002\u5f53\u4f7f\u7528\u57fa\u4e8e\u8bed\u53e5\u7684\u65e5\u5fd7\u8bb0\u5f55\u65f6\uff0c\u8fd9\u79cd\u7d27\u51d1\u7684\u65e5\u5fd7\u8bb0 \u5f55\u4f1a\u81ea\u52a8\u5b8c\u6210\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7\u5c06\u65b0\u7684binlog_row_value_options\u7cfb\u7edf\u53d8\u91cf\u503c\u8bbe\u7f6e\u4e3aPARTIAL_JSON\u6765\u542f\u7528\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.2 MySQL8.0\u79fb\u9664\u7684\u65e7\u7279\u6027<\/h3>\n\n\n\n<p>\u5728MySQL 5.7\u7248\u672c\u4e0a\u5f00\u53d1\u7684\u5e94\u7528\u7a0b\u5e8f\u5982\u679c\u4f7f\u7528\u4e86MySQL8.0 \u79fb\u9664\u7684\u7279\u6027\uff0c\u8bed\u53e5\u53ef\u80fd\u4f1a\u5931\u8d25\uff0c\u6216\u8005\u4ea7\u751f\u4e0d\u540c \u7684\u6267\u884c\u7ed3\u679c\u3002\u4e3a\u4e86\u907f\u514d\u8fd9\u4e9b\u95ee\u9898\uff0c\u5bf9\u4e8e\u4f7f\u7528\u4e86\u79fb\u9664\u7279\u6027\u7684\u5e94\u7528\uff0c\u5e94\u5f53\u5c3d\u529b\u4fee\u6b63\u907f\u514d\u4f7f\u7528\u8fd9\u4e9b\u7279\u6027\uff0c\u5e76\u5c3d \u53ef\u80fd\u4f7f\u7528\u66ff\u4ee3\u65b9\u6cd5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">&nbsp;2. \u65b0\u7279\u60271\uff1a\u7a97\u53e3\u51fd\u6570<\/h2>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"705\" width=\"683\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/a7fe1a86a15b4ef79b6e5d56c739d943.png\" alt=\"\"><\/p>\n\n\n\n<p>&nbsp;\u5982\u679c\u7528\u5206\u7ec4\u548c\u805a\u5408\u51fd\u6570\uff0c\u5c31\u9700\u8981\u5206\u597d\u51e0\u6b65\u6765\u8ba1\u7b97\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e00\u6b65\uff0c\u8ba1\u7b97\u603b\u9500\u552e\u91d1\u989d\uff0c\u5e76\u5b58\u5165\u4e34\u65f6\u8868 a\uff1a<\/p>\n\n\n\n<p>\u7b2c\u4e8c\u6b65\uff0c\u8ba1\u7b97\u6bcf\u4e2a\u57ce\u5e02\u7684\u9500\u552e\u603b\u989d\u5e76\u5b58\u5165\u4e34\u65f6\u8868 b\uff1a<\/p>\n\n\n\n<p>\u7b2c\u4e09\u6b65\uff0c\u8ba1\u7b97\u5404\u533a\u7684\u9500\u552e\u5360\u6240\u5728\u57ce\u5e02\u7684\u603b\u8ba1\u91d1\u989d\u7684\u6bd4\u4f8b\uff0c\u548c\u5360\u5168\u90e8\u9500\u552e\u603b\u8ba1\u91d1\u989d\u7684\u6bd4\u4f8b\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 \u4e0b\u9762\u7684\u8fde\u63a5\u67e5\u8be2\u83b7\u5f97\u9700\u8981\u7684\u7ed3\u679c\uff1a<img loading=\"lazy\" decoding=\"async\" height=\"91\" width=\"531\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/78e7f5ee59774a069e7a23c39b7912e1.png\" alt=\"\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TEMPORARY TABLE a  -- \u521b\u5efa\u4e34\u65f6\u8868\nSELECT SUM(sales_value) AS sales_value -- \u8ba1\u7b97\u603b\u8ba1\u91d1\u989d\nFROM sales;\n\nSELECT * FROM a;\n\nCREATE TEMPORARY TABLE b  -- \u521b\u5efa\u4e34\u65f6\u8868\nSELECT city, SUM(sales_value) AS sales_value -- \u8ba1\u7b97\u57ce\u5e02\u9500\u552e\u5408\u8ba1\nFROM sales\nGROUP BY city;\n\nSELECT * FROM b;\n\nSELECT s.city AS \u57ce\u5e02, s.county AS \u533a, s.sales_value AS \u533a\u9500\u552e\u989d,\nb.sales_value AS \u5e02\u9500\u552e\u989d, s.sales_value\/b.sales_value AS \u5e02\u6bd4\u7387,\na.sales_value AS \u603b\u9500\u552e\u989d, s.sales_value\/a.sales_value AS \u603b\u6bd4\u7387\nFROM sales s\nJOIN b ON (s.city=b.city) -- \u8fde\u63a5\u5e02\u7edf\u8ba1\u7ed3\u679c\u4e34\u65f6\u8868\nJOIN a -- \u8fde\u63a5\u603b\u8ba1\u91d1\u989d\u4e34\u65f6\u8868\nORDER BY s.city, s.county;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u65b9\u6cd5\u4e8c\nSELECT city AS \u57ce\u5e02, county AS \u533a, sales_value AS \u533a\u9500\u552e\u989d,\nSUM(sales_value) OVER(PARTITION BY city) AS \u5e02\u9500\u552e\u989d, -- \u8ba1\u7b97\u5e02\u9500\u552e\u989d\nsales_value\/SUM(sales_value) OVER(PARTITION BY city) AS \u5e02\u6bd4\u7387,\nSUM(sales_value) OVER() AS \u603b\u9500\u552e\u989d, -- \u8ba1\u7b97\u603b\u9500\u552e\u989d\nsales_value\/SUM(sales_value) OVER() AS \u603b\u6bd4\u7387\nFROM sales\nORDER BY city, county;<img loading=\"lazy\" decoding=\"async\" height=\"15\" width=\"15\" src=\"blob:https:\/\/eve2333.top\/77f5ac26-1e8e-46f8-8d55-b0a250f5a3d1\"><\/code><\/pre>\n\n\n\n<p>\u7a97\u53e3\u51fd\u6bcf\u4e00\u6b65\u90fd\u662f\u5355\u72ec\u7684\u7a97\u53e3\uff0c\u4e92\u4e0d\u5e72\u6270\u3002\u4f7f\u7528\u7a97\u53e3\u51fd\u6570\uff0c\u53ea\u7528\u4e86\u4e00\u6b65\u5c31\u5b8c\u6210\u4e86\u67e5\u8be2\u3002\u800c\u4e14\uff0c\u7531\u4e8e\u6ca1\u6709\u7528\u5230\u4e34\u65f6\u8868\uff0c\u6267\u884c\u7684\u6548\u7387\u4e5f\u66f4\u9ad8\u4e86\u3002\u5f88\u663e \u7136\uff0c\u5728\u8fd9\u79cd\u9700\u8981\u7528\u5230\u5206\u7ec4\u7edf\u8ba1\u7684\u7ed3\u679c\u5bf9\u6bcf\u4e00\u6761\u8bb0\u5f55\u8fdb\u884c\u8ba1\u7b97\u7684\u573a\u666f\u4e0b\uff0c\u4f7f\u7528\u7a97\u53e3\u51fd\u6570\u66f4\u597d\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/www.bilibili.com\/video\/BV1iq4y1u7vj?t=2046.5&amp;p=94\" target=\"_blank\"  rel=\"nofollow\" >94-MySQL8.0\u65b0\u7279\u6027_\u7a97\u53e3\u51fd\u6570\u7684\u4f7f\u7528_\u54d4\u54e9\u54d4\u54e9_bilibili<\/a>&nbsp;\u523037.25<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.2 \u7a97\u53e3\u51fd\u6570\u5206\u7c7b<\/h3>\n\n\n\n<p>MySQL\u4ece8.0\u7248\u672c\u5f00\u59cb\u652f\u6301\u7a97\u53e3\u51fd\u6570\u3002\u7a97\u53e3\u51fd\u6570\u7684\u4f5c\u7528\u7c7b\u4f3c\u4e8e\u5728\u67e5\u8be2\u4e2d\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7ec4\uff0c\u4e0d\u540c\u7684\u662f\uff0c\u5206\u7ec4 \u64cd\u4f5c\u4f1a\u628a\u5206\u7ec4\u7684\u7ed3\u679c\u805a\u5408\u6210\u4e00\u6761\u8bb0\u5f55\uff0c\u800c\u7a97\u53e3\u51fd\u6570\u662f\u5c06\u7ed3\u679c\u7f6e\u4e8e\u6bcf\u4e00\u6761\u6570\u636e\u8bb0\u5f55\u4e2d\u3002<strong>\u7a97\u53e3\u51fd\u6570\u76f8\u5f53\u4e8e\u7ed9\u6bcf\u6761\u8bb0\u5f55\u6dfb\u52a0\u4e86\u865a\u62df\u805a\u5408\u7ed3\u679c\u5217\uff1border by \u5e73\u65f6\u7ec3\u4e60\u90fd\u662f\u642d\u914d\u805a\u5408\u51fd\u6570\u7684 \u4f46\u662f\u5355\u72ec\u4f7f\u7528\u662f\u6309\u7167\u90e8\u95e8id\u5f52\u5e76\u5230\u4e00\u6761<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u51fd\u6570\u5206\u7c7b<\/th><th>\u51fd\u6570<\/th><th>\u51fd\u6570\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td>\u5e8f\u53f7\u51fd\u6570<\/td><td>ROW_NUMBER()<\/td><td>\u987a\u5e8f\u6392\u5e8f<\/td><\/tr><tr><td>\u5e8f\u53f7\u51fd\u6570<\/td><td>RANK()<\/td><td>\u5e76\u5217\u6392\u5e8f\uff0c\u4f1a\u8df3\u8fc7\u91cd\u590d\u7684\u5e8f\u53f7\uff0c\u6bd4\u5982\u5e8f\u53f7\u4e3a1\u30011\u30013<\/td><\/tr><tr><td>\u5e8f\u53f7\u51fd\u6570<\/td><td>DENSE_RANK()<\/td><td>\u5e76\u5217\u6392\u5e8f\uff0c\u4e0d\u4f1a\u8df3\u8fc7\u91cd\u590d\u7684\u5e8f\u53f7\uff0c\u6bd4\u5982\u5e8f\u53f7\u4e3a1\u30011\u30012<\/td><\/tr><tr><td>\u5206\u5e03\u51fd\u6570<\/td><td>PERCENT_RANK()<\/td><td>\u7b49\u7ea7\u503c\u767e\u5206\u6bd4<\/td><\/tr><tr><td>\u5206\u5e03\u51fd\u6570<\/td><td>CUME_DIST()<\/td><td>\u7d2f\u79ef\u5206\u5e03\u503c<\/td><\/tr><tr><td>\u524d\u540e\u51fd\u6570<\/td><td>LAG(expr, n)<\/td><td>\u8fd4\u56de\u5f53\u524d\u884c\u7684\u524dn\u884c\u7684expr\u7684\u503c<\/td><\/tr><tr><td>\u524d\u540e\u51fd\u6570<\/td><td>LEAD(expr, n)<\/td><td>\u8fd4\u56de\u5f53\u524d\u884c\u7684\u540en\u884c\u7684expr\u7684\u503c<\/td><\/tr><tr><td>\u9996\u5c3e\u51fd\u6570<\/td><td>FIRST_VALUE(expr)<\/td><td>\u8fd4\u56de\u7b2c\u4e00\u4e2aexpr\u7684\u503c<\/td><\/tr><tr><td>\u9996\u5c3e\u51fd\u6570<\/td><td>LAST_VALUE(expr)<\/td><td>\u8fd4\u56de\u6700\u540e\u4e00\u4e2aexpr\u7684\u503c<\/td><\/tr><tr><td>\u5176\u4ed6\u51fd\u6570<\/td><td>NTH_VALUE(expr, n)<\/td><td>\u8fd4\u56de\u7b2cn\u4e2aexpr\u7684\u503c<\/td><\/tr><tr><td>\u5176\u4ed6\u51fd\u6570<\/td><td>NTILE(n)<\/td><td>\u5c06\u5206\u533a\u4e2d\u7684\u6709\u5e8f\u6570\u636e\u5206\u4e3an\u4e2a\u6876\uff0c\u8bb0\u5f55\u6876\u7f16\u53f7<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>#1. \u5e8f\u53f7\u51fd\u6570\n#1.1 ROW_NUMBER() \u51fd\u6570\n#\u4e3e\u4f8b\uff1a\u67e5\u8be2 goods \u6570\u636e\u8868\u4e2d\u6bcf\u4e2a\u5546\u54c1\u5206\u7c7b\u4e0b\u4ef7\u683c\u964d\u5e8f\u6392\u5217\u7684\u5404\u4e2a\u5546\u54c1\u4fe1\u606f\u3002\nSELECT ROW_NUMBER() OVER(PARTITION BY category_id ORDER BY price DESC) AS row_num,\nid, category_id, category, NAME, price, stock\nFROM goods;\n\n#\u4e3e\u4f8b\uff1a\u67e5\u8be2 goods \u6570\u636e\u8868\u4e2d\u6bcf\u4e2a\u5546\u54c1\u5206\u7c7b\u4e0b\u4ef7\u683c\u6700\u9ad8\u76843\u79cd\u5546\u54c1\u4fe1\u606f\u3002\nSELECT *\nFROM (\n    SELECT ROW_NUMBER() OVER(PARTITION BY category_id ORDER BY price DESC) AS row_num,\n    id, category_id, category, NAME, price, stock\n    FROM goods) t\nWHERE row_num &lt;= 3;\n\n#1.2 RANK() \u51fd\u6570\n#\u4e3e\u4f8b\uff1a\u4f7f\u7528RANK()\u51fd\u6570\u83b7\u53d6 goods \u6570\u636e\u8868\u4e2d\u5404\u7c7b\u522b\u7684\u4ef7\u683c\u4ece\u9ad8\u5230\u4f4e\u6392\u5e8f\u7684\u5404\u5546\u54c1\u4fe1\u606f\u3002\nSELECT RANK() OVER(PARTITION BY category_id ORDER BY price DESC) AS row_num,\nid, category_id, category, NAME, price, stock\nFROM goods;\n\n#2. \u5206\u5e03\u51fd\u6570\n#2.1 PERCENT_RANK() \u51fd\u6570\n#\u4e3e\u4f8b\uff1a\u8ba1\u7b97 goods \u6570\u636e\u8868\u4e2d\u540d\u79f0\u4e3a\u201c\u5973\u88c5\/\u5973\u58eb\u7cbe\u54c1\u201d\u7684\u7c7b\u522b\u4e0b\u7684\u5546\u54c1\u7684PERCENT_RANK\u503c\u3002\n# \u65b9\u5f0f1:\nSELECT RANK() OVER w AS r,\nPERCENT_RANK() OVER w AS pr,\nid, category_id, category, NAME, price, stock\nFROM goods\nWHERE category_id = 1 WINDOW w AS (PARTITION BY category_id ORDER BY price DESC);\n\n# \u65b9\u5f0f2:\nSELECT RANK() OVER (PARTITION BY category_id ORDER BY price DESC) AS r,\nPERCENT_RANK() OVER (PARTITION BY category_id ORDER BY price DESC) AS pr,\nid, category_id, category, NAME, price, stock\nFROM goods\nWHERE category_id = 1;\n\n#2.2 CUME_DIST() \u51fd\u6570\n#\u4e3e\u4f8b\uff1a\u67e5\u8be2goods\u6570\u636e\u8868\u4e2d\u5c0f\u4e8e\u6216\u7b49\u4e8e\u5f53\u524d\u4ef7\u683c\u7684\u6bd4\u4f8b\u3002\nSELECT CUME_DIST() OVER (PARTITION BY category_id ORDER BY price ASC) AS cd,\nid, category, NAME, price\nFROM goods;\n\n#3. \u524d\u540e\u51fd\u6570\n#3.1 LAG(expr, n) \u51fd\u6570\n#\u4e3e\u4f8b\uff1a\u67e5\u8be2goods\u6570\u636e\u8868\u4e2d\u524d\u4e00\u4e2a\u5546\u54c1\u4ef7\u683c\u4e0e\u5f53\u524d\u5546\u54c1\u4ef7\u683c\u7684\u5dee\u503c\u3002\nSELECT id, category, NAME, price, pre_price, price - pre_price AS diff_price\nFROM (\n    SELECT id, category, NAME, price, LAG(price, 1) OVER w AS pre_price\n    FROM goods\n    WINDOW w AS (PARTITION BY category_id ORDER BY price)) t;\n\n\u5176\u4e2d\u5b50\u67e5\u8be2\u5982\u4e0b\nSELECT id, category, NAME, price, LAG(price, 1) OVER (PARTITION BY category_id ORDER BY price) AS pre_price\nFROM goods\n\n#3.2 LEAD(expr, n) \u51fd\u6570\n#\u4e3e\u4f8b\uff1a\u67e5\u8be2goods\u6570\u636e\u8868\u4e2d\u540e\u4e00\u4e2a\u5546\u54c1\u4ef7\u683c\u4e0e\u5f53\u524d\u5546\u54c1\u4ef7\u683c\u7684\u5dee\u503c\u3002\nSELECT id, category, NAME, price, behind_price, behind_price - price AS diff_price\nFROM (\n    SELECT id, category, NAME, price, LEAD(price, 1) OVER w AS behind_price\n    FROM goods\n    WINDOW w AS (PARTITION BY category_id ORDER BY price)) t;\n\n\u5176\u4e2d\uff0c\u5b50\u67e5\u8be2\u4e3a:\nSELECT id, category, NAME, price, LEAD(price, 1) OVER (PARTITION BY category_id ORDER BY price) AS behind_price\nFROM goods\n\n#4. \u9996\u5c3e\u51fd\u6570\n#4.1 FIRST_VALUE(expr) \u51fd\u6570\n#\u4e3e\u4f8b\uff1a\u6309\u7167\u4ef7\u683c\u6392\u5e8f\uff0c\u67e5\u8be2\u7b2c1\u4e2a\u5546\u54c1\u7684\u4ef7\u683c\u4fe1\u606f\u3002\nSELECT id, category, NAME, price, stock, FIRST_VALUE(price) OVER (PARTITION BY category_id ORDER BY price) AS first_price\nFROM goods\n\n#4.2 LAST_VALUE(expr) \u51fd\u6570\n\n#5. \u5176\u4ed6\u51fd\u6570\n#5.1 NTH_VALUE(expr, n) \u51fd\u6570\n#\u4e3e\u4f8b\uff1a\u67e5\u8be2goods\u6570\u636e\u8868\u4e2d\u6392\u540d\u7b2c2\u548c\u7b2c3\u7684\u4ef7\u683c\u4fe1\u606f\u3002\nSELECT id, category, NAME, price,\nNTH_VALUE(price, 2) OVER (PARTITION BY category_id ORDER BY price) AS second_price,\nNTH_VALUE(price, 3) OVER (PARTITION BY category_id ORDER BY price) AS third_price\nFROM goods\n\n#5.2 NTILE(n) \u51fd\u6570\n#\u4e3e\u4f8b\uff1a\u5c06goods\u8868\u4e2d\u7684\u5546\u54c1\u6309\u7167\u4ef7\u683c\u5206\u4e3a3\u7ec4\u3002\nSELECT NTILE(3) OVER (PARTITION BY category_id ORDER BY price) AS nt, id, category, NAME, price\nFROM goods;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">&nbsp;3. \u65b0\u7279\u60272\uff1a\u516c\u7528\u8868\u8868\u8fbe\u5f0f<\/h2>\n\n\n\n<p>&nbsp;&nbsp;<a href=\"https:\/\/www.bilibili.com\/video\/BV1iq4y1u7vj?spm_id_from=333.788.player.switch&amp;vd_source=b31958e33027799323b8b7d77ae181d4&amp;p=95\" target=\"_blank\"  rel=\"nofollow\" >95-\u516c\u7528\u8868\u8868\u8fbe\u5f0f_\u8bfe\u540e\u7ec3\u4e60_\u6700\u540e\u5bc4\u8bed_\u54d4\u54e9\u54d4\u54e9_bilibili<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u8bfe\u540e\u7ec3\u4e60<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u7b2c18\u7ae0_MySQL8.0\u7684\u5176\u5b83\u65b0\u7279\u6027\u7684\u8bfe\u540e\u7ec3\u4e60\n\n#1. \u521b\u5efastudents\u6570\u636e\u8868\uff0c\u5982\u4e0b\n\nCREATE DATABASE test18_mysql8;\n\nUSE test18_mysql8;\n\nCREATE TABLE students(\nid INT PRIMARY KEY AUTO_INCREMENT,\nstudent VARCHAR(15),\npoints TINYINT\n);\n\n#2. \u5411\u8868\u4e2d\u6dfb\u52a0\u6570\u636e\u5982\u4e0b\nINSERT INTO students(student,points)\nVALUES\n('\u5f20\u4e09',89),\n('\u674e\u56db',77),\n('\u738b\u4e94',88),\n('\u8d75\u516d',90),\n('\u5b59\u4e03',90),\n('\u5468\u516b',88);\n\nSELECT * FROM students;\n\n#3. \u5206\u522b\u4f7f\u7528RANK()\u3001DENSE_RANK() \u548c ROW_NUMBER()\u51fd\u6570\u5bf9\u5b66\u751f\u6210\u7ee9\u964d\u5e8f\u6392\u5217\u60c5\u51b5\u8fdb\u884c\u663e\u793a\n#\u65b9\u5f0f1\uff1a\nSELECT \nROW_NUMBER() OVER (ORDER BY points DESC) AS \"\u6392\u5e8f1\",\nRANK() OVER (ORDER BY points DESC) AS \"\u6392\u5e8f2\",\nDENSE_RANK() OVER (ORDER BY points DESC) AS \"\u6392\u5e8f3\",\nstudent,points\nFROM students;\n\n\n#\u65b9\u5f0f2\uff1a\nSELECT \nROW_NUMBER() OVER w AS \"\u6392\u5e8f1\",\nRANK() OVER w AS \"\u6392\u5e8f2\",\nDENSE_RANK() OVER w AS \"\u6392\u5e8f3\",\nstudent,points\nFROM students WINDOW w AS (ORDER BY points DESC);<img loading=\"lazy\" decoding=\"async\" height=\"15\" width=\"15\" src=\"blob:https:\/\/eve2333.top\/e9436132-e656-4d05-9d8b-135c5ca84301\"><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c18\u7ae0_MySQL8\u5176\u5b83\u65b0\u7279\u6027 \u6bd4\u5982\u7f16\u7801\u8bbe\u8ba1\u57288.0\u540e\u76f4\u63a5\u9ed8\u8ba4utf8mb4\uff0c\u89e3\u51b3\u7f16\u7801\u95ee\u9898\uff1b\u8fd8\u6709\u767b\u5f55\u52a0\u5bc6\u65b9\u5f0f\u7684\u6dfb\u52a0 1. MyS &#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":[2],"tags":[16],"class_list":["post-878","post","type-post","status-publish","format-standard","hentry","category-2","tag-sql"],"_links":{"self":[{"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts\/878","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=878"}],"version-history":[{"count":1,"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts\/878\/revisions"}],"predecessor-version":[{"id":879,"href":"https:\/\/eve2333.top\/index.php?rest_route=\/wp\/v2\/posts\/878\/revisions\/879"}],"wp:attachment":[{"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=878"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=878"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eve2333.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=878"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}