{"id":121615,"date":"2026-11-03T05:08:35","date_gmt":"2026-11-02T21:08:35","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/121615.html"},"modified":"2026-11-03T05:08:35","modified_gmt":"2026-11-02T21:08:35","slug":"%e4%b8%89%e4%bb%bd%e5%90%8d%e5%8d%95%e9%95%bf%e7%9f%ad%e4%b8%8d%e5%90%8c%ef%bc%8csql%e6%80%8e%e4%b9%88%e6%a8%aa%e7%9d%80%e6%8e%92%ef%bc%9f%e5%85%88%e7%bb%99%e6%af%8f%e7%bb%84%e5%ad%a6%e7%94%9f","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/121615.html","title":{"rendered":"\u4e09\u4efd\u540d\u5355\u957f\u77ed\u4e0d\u540c\uff0cSQL\u600e\u4e48\u6a2a\u7740\u6392\uff1f\u5148\u7ed9\u6bcf\u7ec4\u5b66\u751f\u627e\u4e2a\u4f4d\u7f6e"},"content":{"rendered":"<h2>\u4e09\u4efd\u540d\u5355\u957f\u77ed\u4e0d\u540c&#xff0c;SQL\u600e\u4e48\u6a2a\u7740\u6392&#xff1f;\u5148\u7ed9\u6bcf\u7ec4\u5b66\u751f\u627e\u4e2a\u4f4d\u7f6e<\/h2>\n<p>\u5047\u8bbe\u624b\u91cc\u6709\u4e09\u4efd\u5b66\u751f\u540d\u5355&#xff0c;\u8981\u653e\u8fdb\u4e00\u5f20\u62a5\u8868\u91cc&#xff1a;\u4e9a\u6d32\u4e00\u5217&#xff0c;\u6b27\u6d32\u4e00\u5217&#xff0c;\u7f8e\u6d32\u4e00\u5217\u3002\u6bcf\u5217\u6309\u59d3\u540d\u6392\u5e8f&#xff0c;\u54ea\u4efd\u540d\u5355\u5148\u6392\u5b8c&#xff0c;\u540e\u9762\u7684\u683c\u5b50\u5c31\u7559\u7a7a\u3002<\/p>\n<p>\u8fd9\u542c\u8d77\u6765\u4e0d\u590d\u6742&#xff0c;\u590d\u5236\u5230\u8868\u683c\u91cc\u5c31\u80fd\u6446\u51fa\u6765\u3002\u4f46\u5728\u6570\u636e\u5e93\u91cc&#xff0c;\u5b66\u751f\u539f\u672c\u662f\u4e00\u884c\u4e00\u884c\u5b58\u7684\u3002\u6211\u4eec\u5148\u4e0d\u8981\u627e\u201c\u884c\u8f6c\u5217\u6a21\u677f\u201d&#xff0c;\u770b\u6e05\u695a\u8981\u600e\u6837\u6446\u3002<\/p>\n<p>\u4e0b\u9762\u8fd9\u9053\u7ec3\u4e60\u6765\u81ea\u65e7SQL\u7b14\u8bb0\u4e2d\u201c\u6309\u5730\u533a\u6574\u7406\u5b66\u751f\u62a5\u8868\u201d\u7684\u9009\u9898\u3002\u7b14\u8bb0\u63d0\u5230\u8fc7LeetCode 618&#xff0c;\u4e0d\u8fc7\u5b98\u65b9\u9898\u9875\u5f53\u524d\u9700\u8981\u8ba2\u9605\u624d\u80fd\u8bfb\u5b8c\u6574\u9898\u9762&#xff0c;\u6240\u4ee5\u8fd9\u91cc\u81ea\u884c\u7ea6\u5b9a\u8868\u7ed3\u6784\u548c\u89c4\u5219&#xff0c;\u4e0d\u628a\u5b83\u5f53\u6210\u5b98\u65b9\u539f\u9898\u590d\u8ff0\u3002<\/p>\n<h3>\u5148\u4e0d\u7528SQL&#xff0c;\u628a\u540d\u5355\u6392\u4e00\u6b21<\/h3>\n<p>\u6211\u4eec\u4f7f\u7528\u8fd96\u6761\u8bb0\u5f55\u3002student_id\u552f\u4e00&#xff1b;\u59d3\u540d\u548c\u5730\u533a\u90fd\u4e0d\u4e3a\u7a7a&#xff0c;\u59d3\u540d\u53ea\u7528\u5927\u5199\u82f1\u6587\u5b57\u6bcd\u3002\u5730\u533a\u9650\u5b9a\u4e3aAsia\u3001Europe\u3001America\u3002\u540c\u540d\u7b97\u4e0d\u540c\u5b66\u751f&#xff0c;\u540c\u540d\u65f6\u6309\u7f16\u53f7\u4ece\u5c0f\u5230\u5927\u6392\u3002<\/p>\n<p>\u5728\u7a7a\u7684MySQL 8\u5b66\u4e60\u5e93\u4e2d\u6267\u884c&#xff1b;\u6709\u540c\u540d\u8868\u5c31\u6362\u5e93&#xff0c;\u4e0d\u8981\u8986\u76d6\u4e1a\u52a1\u8868\u3002<\/p>\n<p>CREATE TABLE Student (<br \/>\n    student_id INT PRIMARY KEY,<br \/>\n    name VARCHAR(20) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,<br \/>\n    continent ENUM(&#039;Asia&#039;,&#039;Europe&#039;,&#039;America&#039;) NOT NULL<br \/>\n);<br \/>\nINSERT INTO Student VALUES<br \/>\n    (30, &#039;BO&#039;, &#039;Asia&#039;),<br \/>\n    (11, &#039;ADA&#039;, &#039;Europe&#039;),<br \/>\n    (9, &#039;AMY&#039;, &#039;Asia&#039;),<br \/>\n    (24, &#039;CARL&#039;, &#039;America&#039;),<br \/>\n    (3, &#039;AMY&#039;, &#039;Asia&#039;),<br \/>\n    (8, &#039;BEN&#039;, &#039;Europe&#039;);<\/p>\n<p>\u4e3a\u4ec0\u4e48\u7279\u610f\u5199\u4e24\u4e2aAMY&#xff1f;\u56e0\u4e3a\u6211\u4eec\u6392\u7684\u662f\u5b66\u751f&#xff0c;\u4e0d\u662f\u4e0d\u540c\u59d3\u540d\u7684\u96c6\u5408\u3002\u4e24\u540d\u540c\u540d\u5b66\u751f\u90fd\u5f97\u5360\u4e00\u4e2a\u4f4d\u7f6e\u3002<\/p>\n<p>\u5148\u628a\u5730\u533a\u62c6\u5f00&#xff0c;\u5404\u81ea\u6392\u5e8f&#xff1a;<\/p>\n<p>Asia          Europe       America<br \/>\nAMY(id&#061;3)     ADA(id&#061;11)   CARL(id&#061;24)<br \/>\nAMY(id&#061;9)     BEN(id&#061;8)<br \/>\nBO(id&#061;30)<\/p>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u62ff\u4e09\u4efd\u540d\u5355\u91cc\u7684\u7b2c\u4e00\u4eba\u653e\u4e00\u884c&#xff0c;\u7b2c\u4e8c\u4eba\u653e\u4e0b\u4e00\u884c\u3002\u6700\u540e\u5e94\u8be5\u662f&#xff1a;<\/p>\n<p>\u4f4d\u7f6e  Asia  Europe  America<br \/>\n 1    AMY   ADA     CARL<br \/>\n 2    AMY   BEN     NULL<br \/>\n 3    BO    NULL    NULL<\/p>\n<p>\u8fd9\u91cc\u7528SQL\u7684NULL\u8868\u793a\u6ca1\u6709\u5b66\u751f&#xff0c;\u5e76\u4e0d\u662f\u59d3\u540d\u53eb\u201cNULL\u201d&#xff0c;\u4e5f\u4e0d\u662f\u628a\u7a7a\u683c\u5f53\u6210\u59d3\u540d\u5b58\u8fdb\u53bb\u3002\u6700\u7ec8\u67e5\u8be2\u53ea\u8fd4\u56de\u4e09\u4e2a\u5730\u533a\u5217&#xff0c;\u201c\u4f4d\u7f6e\u201d\u6682\u65f6\u7528\u6765\u5e2e\u6211\u4eec\u770b\u5bf9\u9f50\u8fc7\u7a0b\u3002<\/p>\n<p>\u6ce8\u610f&#xff0c;\u540c\u4e00\u884c\u7684\u4e09\u4e2a\u4eba\u6ca1\u6709\u4e1a\u52a1\u4e0a\u7684\u8054\u7cfb\u3002\u7b2c\u4e00\u884c\u5e76\u4e0d\u662f\u540c\u73ed\u3001\u540c\u4e00\u5929\u5165\u5b66&#xff0c;\u6216\u8005\u7f16\u53f7\u76f8\u540c&#xff0c;\u53ea\u662f\u5404\u81ea\u5728\u672c\u5730\u533a\u6392\u5230\u7b2c\u4e00\u4f4d\u3002<\/p>\n<h3>\u76f4\u63a5JOIN&#xff0c;\u4e3a\u4ec0\u4e48\u8d8a\u62fc\u4eba\u8d8a\u591a&#xff1f;<\/h3>\n<p>\u5982\u679c\u5148\u67e5\u4e9a\u6d32\u540d\u5355&#xff0c;\u518d\u548c\u6b27\u6d32\u540d\u5355\u3001\u7f8e\u6d32\u540d\u5355\u62fc\u5728\u4e00\u8d77&#xff0c;\u4f1a\u4e0d\u4f1a\u5c31\u5f97\u5230\u8fd9\u5f20\u8868&#xff1f;<\/p>\n<p>\u60f3\u4e00\u4e0b\u7b2c\u4e00\u4f4d\u4e9a\u6d32\u5b66\u751fAMY(id&#061;3)\u3002\u6b27\u6d32\u6709ADA\u3001BEN\u4e24\u4f4d&#xff0c;\u6ca1\u6709\u989d\u5916\u7684\u5339\u914d\u6761\u4ef6\u65f6&#xff0c;\u8fd9\u4e2aAMY\u4f1a\u548c\u4e24\u4eba\u5206\u522b\u62fc\u4e00\u6b21\u3002<\/p>\n<p>AMY(id&#061;3) &#8212; ADA<br \/>\n          &#8212; BEN<\/p>\n<p>\u53e6\u5916\u4e24\u4e2a\u4e9a\u6d32\u5b66\u751f\u4e5f\u5404\u62fc\u4e24\u6b21\u3002\u4e09\u5217\u8fd9\u6837\u505a\u7b1b\u5361\u5c14\u79ef&#xff0c;\u4e00\u5171\u662f3\u00d72\u00d71&#061;6\u884c&#xff0c;\u800c\u6211\u4eec\u8981\u7684\u662f3\u884c\u3002\u4e00\u65e6\u67d0\u4e2a\u5730\u533a\u65e0\u4eba&#xff0c;\u4ea4\u53c9\u8fde\u63a5\u751a\u81f3\u53ef\u80fd\u628a\u6574\u5f20\u62a5\u8868\u53d8\u6210\u7a7a\u7ed3\u679c\u3002<\/p>\n<p>\u73b0\u5728\u7f3a\u7684\u4e0d\u662f\u4e00\u4e2a\u66f4\u5de7\u7684\u8fde\u63a5\u6761\u4ef6&#xff0c;\u800c\u662f&#xff1a;\u8c01\u5e94\u8be5\u548c\u8c01\u653e\u5728\u540c\u4e00\u884c&#xff1f;<\/p>\n<p>\u624b\u5de5\u6392\u8868\u65f6&#xff0c;\u6211\u4eec\u5176\u5b9e\u5df2\u7ecf\u6709\u4e86\u7b54\u6848&#xff1a;\u5404\u5730\u533a\u7684\u7b2c\u4e00\u4eba\u653e\u4e00\u8d77&#xff0c;\u7b2c\u4e8c\u4eba\u653e\u4e00\u8d77\u3002\u90a3\u5c31\u5728\u67e5\u8be2\u91cc\u628a\u8fd9\u4e2a\u201c\u7b2c\u51e0\u4eba\u201d\u7b97\u51fa\u6765\u3002<\/p>\n<h3>\u7f16\u53f7\u8981\u4ece\u6bcf\u4e2a\u5730\u533a\u91cd\u65b0\u5f00\u59cb<\/h3>\n<p>ROW_NUMBER()\u80fd\u4f9d\u6b21\u7ed9\u8bb0\u5f55\u7f16\u53f7\u3002\u8fd9\u91cc\u4e0d\u80fd\u7ed9\u5168\u8868\u4ece1\u6392\u52306&#xff0c;\u800c\u8981\u5728\u6bcf\u4e2a\u5730\u533a\u91cc\u5206\u522b\u4ece1\u5f00\u59cb\u3002<\/p>\n<p>SELECT student_id, name, continent,<br \/>\n       ROW_NUMBER() OVER (<br \/>\n           PARTITION BY continent<br \/>\n           ORDER BY name, student_id<br \/>\n       ) AS pos<br \/>\nFROM Student<br \/>\nORDER BY continent, pos;<\/p>\n<p>PARTITION BY continent\u628a\u7f16\u53f7\u8303\u56f4\u5206\u5f00&#xff0c;ORDER BY name, student_id\u51b3\u5b9a\u6bcf\u4e2a\u8303\u56f4\u91cc\u8c01\u5728\u524d\u9762\u3002\u8868\u4e2d\u63d2\u5165\u7684\u5148\u540e\u987a\u5e8f\u4e0d\u5f71\u54cd\u8fd9\u4e2a\u7ea6\u5b9a\u3002<\/p>\n<p>\u8fd0\u884c\u540e&#xff0c;\u6309\u6211\u4eec\u5efa\u8868\u65f6ENUM\u7684\u5730\u533a\u987a\u5e8f\u663e\u793a&#xff1a;<\/p>\n<p>id  name  continent  pos<br \/>\n 3  AMY   Asia        1<br \/>\n 9  AMY   Asia        2<br \/>\n30  BO    Asia        3<br \/>\n11  ADA   Europe      1<br \/>\n 8  BEN   Europe      2<br \/>\n24  CARL  America     1<\/p>\n<p>\u4e24\u4e2aAMY\u7684\u4f4d\u7f6e\u4e0d\u540c\u3002\u8fd9\u6b63\u662f\u6211\u4eec\u9700\u8981\u7684\u201c\u7b2c\u4e00\u540d\u5b66\u751f\u3001\u7b2c\u4e8c\u540d\u5b66\u751f\u201d&#xff0c;\u4e0d\u662f\u8003\u8bd5\u540d\u6b21\u3002<\/p>\n<p>\u5982\u679c\u6539\u6210RANK() OVER (PARTITION BY continent ORDER BY name)&#xff0c;\u4e24\u4e2aAMY\u90fd\u4f1a\u6392\u7b2c1&#xff0c;BO\u6392\u7b2c3\u3002\u540e\u9762\u518d\u6309\u4f4d\u7f6e\u5206\u7ec4&#xff0c;\u4e24\u4e2aAMY\u5c31\u6324\u5230\u4e86\u540c\u4e00\u4e2a\u683c\u5b50\u91cc\u3002DENSE_RANK\u867d\u7136\u4e0d\u4f1a\u8df3\u53f7&#xff0c;\u4e5f\u8fd8\u662f\u8ba9\u540c\u540d\u5b66\u751f\u5171\u7528\u4f4d\u7f6e&#xff0c;\u95ee\u9898\u5e76\u6ca1\u6709\u89e3\u51b3\u3002<\/p>\n<p>\u5982\u679c\u7ed9RANK\u7684\u6392\u5e8f\u4e5f\u52a0\u4e0a\u552f\u4e00\u7f16\u53f7&#xff0c;\u540c\u540d\u5b66\u751f\u4e0d\u518d\u5e76\u5217&#xff0c;\u672c\u4f8b\u53ef\u4ee5\u6392\u5bf9\u3002\u4f46\u8fd9\u91cc\u65e2\u7136\u8981\u7684\u662f\u4e00\u4eba\u4e00\u4e2a\u4f4d\u7f6e&#xff0c;\u76f4\u63a5\u4f7f\u7528ROW_NUMBER\u66f4\u8d34\u8fd1\u9700\u6c42\u3002<\/p>\n<h3>\u6709\u4e86\u4f4d\u7f6e&#xff0c;\u518d\u628a\u4e00\u884c\u91cc\u7684\u4e09\u4e2a\u683c\u5b50\u586b\u51fa\u6765<\/h3>\n<p>\u628a\u521a\u624d\u7684\u67e5\u8be2\u547d\u540d\u4e3aranked\u3002\u73b0\u5728\u53ea\u770bpos&#061;1\u7684\u4e09\u6761\u8bb0\u5f55&#xff0c;\u5148\u4e0d\u6025\u7740\u5408\u5e76&#xff1a;<\/p>\n<p>\u539f\u6765&#xff1a;<br \/>\nAMY   Asia      1<br \/>\nADA   Europe    1<br \/>\nCARL  America   1<\/p>\n<p>\u53ea\u586b\u81ea\u5df1\u7684\u5730\u533a\u5217&#xff1a;<br \/>\nAsia  Europe  America<br \/>\nAMY   NULL    NULL<br \/>\nNULL  ADA     NULL<br \/>\nNULL  NULL    CARL<\/p>\n<p>\u201c\u53ea\u586b\u81ea\u5df1\u7684\u5217\u201d\u53ef\u4ee5\u7528CASE\u5199&#xff1a;\u5f53\u524d\u8bb0\u5f55\u662fAsia&#xff0c;\u5c31\u628a\u59d3\u540d\u653e\u8fdbAsia\u5217&#xff0c;\u5426\u5219\u7ed9NULL\u3002\u53e6\u4e24\u5217\u540c\u7406\u3002<\/p>\n<p>\u8fd9\u65f6\u8fd8\u53ea\u662f\u4e09\u884c\u7a00\u758f\u7684\u683c\u5b50\u3002\u8981\u5408\u6210\u4e00\u884c&#xff0c;\u53ef\u4ee5\u6309\u4f4d\u7f6e\u5206\u7ec4&#xff0c;\u7136\u540e\u6bcf\u5217\u53d6\u51fa\u90a3\u4e2a\u975e\u7a7a\u59d3\u540d\u3002<\/p>\n<p>WITH ranked AS (<br \/>\n    SELECT student_id, name, continent,<br \/>\n           ROW_NUMBER() OVER (<br \/>\n               PARTITION BY continent ORDER BY name, student_id<br \/>\n           ) AS pos<br \/>\n    FROM Student<br \/>\n)<br \/>\nSELECT pos,<br \/>\n       CASE WHEN continent &#061; &#039;Asia&#039; THEN name END AS Asia,<br \/>\n       CASE WHEN continent &#061; &#039;Europe&#039; THEN name END AS Europe,<br \/>\n       CASE WHEN continent &#061; &#039;America&#039; THEN name END AS America<br \/>\nFROM ranked<br \/>\nORDER BY pos, continent;<\/p>\n<p>CASE\u6ca1\u6709\u5199ELSE&#xff0c;\u4e0d\u5339\u914d\u65f6\u8fd4\u56deNULL\u3002\u540c\u4e00\u4e2a\u4f4d\u7f6e\u91cc&#xff0c;\u6bcf\u4e2a\u5730\u533a\u6700\u591a\u4e00\u4f4d\u5b66\u751f&#xff0c;\u6240\u4ee5\u6bcf\u5217\u6700\u591a\u53ea\u6709\u4e00\u4e2a\u975e\u7a7a\u503c\u3002<\/p>\n<p>MAX\u4f1a\u5ffd\u7565NULL&#xff1a;AMY\u3001NULL\u3001NULL\u53d6\u51faAMY&#xff1b;\u5168\u90e8\u662fNULL&#xff0c;\u7ed3\u679c\u8fd8\u662fNULL\u3002\u8fd9\u91cc\u7528MAX\u5e76\u4e0d\u662f\u60f3\u627e\u59d3\u540d\u6700\u5927\u7684\u5b66\u751f&#xff0c;\u800c\u662f\u628a\u521a\u624d\u6563\u5f00\u7684\u4e09\u4e2a\u683c\u5b50\u5408\u5e76\u8d77\u6765\u3002<\/p>\n<p>\u8fd9\u4e5f\u8bf4\u660e\u4e3a\u4ec0\u4e48\u524d\u9762\u7684\u7f16\u53f7\u4e0d\u80fd\u9519&#xff1a;\u5982\u679c\u540c\u4e00\u5730\u533a\u6709\u4e24\u4eba\u5171\u7528\u4e00\u4e2a\u4f4d\u7f6e&#xff0c;MAX\u53ea\u4f1a\u53d6\u5176\u4e2d\u4e00\u4e2a\u503c&#xff0c;\u4e0d\u4f1a\u66ff\u6211\u4eec\u53d1\u73b0\u4eba\u6570\u4e22\u4e86\u3002\u540c\u540d\u65f6&#xff0c;\u62a5\u8868\u751a\u81f3\u770b\u4e0d\u51fa\u5c11\u4e86\u4e00\u4eba\u3002<\/p>\n<h3>\u5b8c\u6574\u67e5\u8be2<\/h3>\n<p>WITH ranked AS (<br \/>\n    SELECT name, continent,<br \/>\n           ROW_NUMBER() OVER (<br \/>\n               PARTITION BY continent ORDER BY name, student_id<br \/>\n           ) AS pos<br \/>\n    FROM Student<br \/>\n)<br \/>\nSELECT MAX(CASE WHEN continent &#061; &#039;Asia&#039; THEN name END) AS Asia,<br \/>\n       MAX(CASE WHEN continent &#061; &#039;Europe&#039; THEN name END) AS Europe,<br \/>\n       MAX(CASE WHEN continent &#061; &#039;America&#039; THEN name END) AS America<br \/>\nFROM ranked<br \/>\nGROUP BY pos<br \/>\nORDER BY pos;<\/p>\n<p>\u7ed3\u679c\u5c31\u662f\u524d\u9762\u624b\u5de5\u6392\u7684\u4e09\u884c\u3002\u7b2c\u4e8c\u884c\u7684America\u3001\u7b2c\u4e09\u884c\u7684Europe\u548cAmerica\u90fd\u8865NULL\u3002<\/p>\n<p>\u8fd9\u6b21GROUP BY\u786e\u5b9e\u628a\u591a\u6761\u5b66\u751f\u8bb0\u5f55\u5408\u5e76\u4e86&#xff0c;\u4f46\u5408\u5e76\u7684\u662f\u201c\u6392\u5728\u540c\u4e00\u4e2a\u4f4d\u7f6e\u201d\u7684\u8bb0\u5f55&#xff0c;\u4e0d\u662f\u628a\u4e00\u4e2a\u5730\u533a\u6240\u6709\u5b66\u751f\u538b\u6210\u4e00\u884c\u3002\u5206\u7ec4\u7684\u5bf9\u8c61\u4e00\u53d8&#xff0c;\u62a5\u8868\u542b\u4e49\u5c31\u4e0d\u540c\u3002<\/p>\n<p>\u8fd8\u6709\u4e24\u4e2a\u5bb9\u6613\u5ffd\u7565\u7684\u60c5\u51b5&#xff1a;<\/p>\n<ul>\n<li>\u5982\u679c\u53ea\u6709Europe\u6709\u4eba&#xff0c;\u4f9d\u7136\u5e94\u6309\u6b27\u6d32\u540d\u5355\u751f\u6210\u884c&#xff0c;Asia\u548cAmerica\u6574\u5217\u4e3aNULL\u3002\u4e0d\u80fd\u628a\u67d0\u4e2a\u6307\u5b9a\u5730\u533a\u7684\u540d\u5355\u5f53\u4f5c\u62a5\u8868\u7684\u552f\u4e00\u4e3b\u8868\u3002<\/li>\n<li>\u5982\u679c\u4e09\u4e2a\u5730\u533a\u90fd\u6ca1\u4eba&#xff0c;\u8fd4\u56de\u96f6\u884c\u5373\u53ef&#xff1b;\u6211\u4eec\u6ca1\u6709\u8981\u6c42\u51ed\u7a7a\u9020\u4e00\u884c\u4e09\u4e2aNULL\u3002<\/li>\n<\/ul>\n<p>\u8f93\u51fa\u6709\u591a\u5c11\u884c&#xff1f;\u662f\u4e09\u4e2a\u5730\u533a\u4eba\u6570\u7684\u6700\u5927\u503c\u3002\u56e0\u4e3a\u6700\u957f\u7684\u540d\u5355\u6392\u5230\u54ea\u91cc&#xff0c;\u90a3\u91cc\u81f3\u5c11\u8fd8\u6709\u4e00\u4e2a\u683c\u5b50\u975e\u7a7a\u3002\u8fd9\u6761\u89c4\u5f8b\u4e5f\u53ef\u4ee5\u62ff\u6765\u68c0\u67e5\u6709\u6ca1\u6709\u6f0f\u884c&#xff0c;\u4f46\u4ec5\u68c0\u67e5\u884c\u6570\u8fd8\u4e0d\u591f&#xff0c;\u59d3\u540d\u548c\u987a\u5e8f\u4ecd\u53ef\u80fd\u4e0d\u5bf9\u3002<\/p>\n<p>\u8fd9\u91cc\u7684\u4e09\u4e2a\u5730\u533a\u662f\u56fa\u5b9a\u5217\u3002\u589e\u52a0Africa\u5e76\u4e0d\u53ea\u662f\u5f80\u8868\u91cc\u52a0\u6570\u636e&#xff0c;\u8fd8\u9700\u8981\u7ed9\u67e5\u8be2\u589e\u52a0\u5bf9\u5e94\u7684CASE\u548c\u8f93\u51fa\u5217\u3002\u5982\u679c\u5217\u7684\u79cd\u7c7b\u7531\u7528\u6237\u4e34\u65f6\u51b3\u5b9a&#xff0c;\u5c31\u5df2\u7ecf\u662f\u52a8\u6001\u62a5\u8868\u7684\u53e6\u4e00\u4e2a\u95ee\u9898\u4e86\u3002\u4e2d\u6587\u59d3\u540d\u3001\u5927\u5c0f\u5199\u6216\u91cd\u97f3\u7684\u6392\u5217\u89c4\u5219&#xff0c;\u4e5f\u8981\u91cd\u65b0\u7ea6\u5b9a\u6392\u5e8f\u89c4\u5219&#xff0c;\u4e0d\u80fd\u62ff\u672c\u4f8b\u7684ASCII\u987a\u5e8f\u4ee3\u66ff\u3002<\/p>\n<h3>\u9a8c\u8bc1\u7a0b\u5e8f\u600e\u4e48\u8bbe\u8ba1&#xff1f;<\/h3>\n<p>\u53c2\u8003\u7a0b\u5e8f\u4e0d\u7528\u7a97\u53e3\u51fd\u6570&#xff0c;\u4e5f\u4e0d\u518d\u5199\u4e00\u6b21\u6761\u4ef6\u805a\u5408\u3002\u5b83\u5148\u5728Python\u91cc\u51c6\u5907\u4e09\u4e2a\u5217\u8868&#xff0c;\u628a\u5b66\u751f\u6309\u5730\u533a\u653e\u8fdb\u53bb&#xff0c;\u5404\u81ea\u6309\u59d3\u540d\u548c\u7f16\u53f7\u6392\u5e8f&#xff0c;\u7136\u540e\u50cf\u6587\u7ae0\u5f00\u5934\u90a3\u6837\u9010\u4e2a\u4f4d\u7f6e\u53d6\u4eba&#xff0c;\u77ed\u540d\u5355\u53d6\u4e0d\u5230\u5c31\u8865NULL\u3002<\/p>\n<p>\u518d\u628a\u76f8\u540c\u7684\u6570\u636e\u4ea4\u7ed9\u72ec\u7acbMySQL\u5b9e\u4f8b&#xff0c;\u6267\u884c\u4ece\u672c\u6587\u63d0\u53d6\u7684\u67e5\u8be2&#xff0c;\u9010\u884c\u6bd4\u8f83\u4e09\u5217\u59d3\u540d\u53ca\u987a\u5e8f\u3002\u8fd9\u6837\u6bd4\u8f83\u7684\u662f\u540c\u4e00\u4efd\u8f93\u5165\u7ecf\u8fc7\u4e24\u79cd\u4e0d\u540c\u7ec4\u7ec7\u65b9\u5f0f\u540e&#xff0c;\u80fd\u4e0d\u80fd\u5f97\u5230\u540c\u4e00\u5f20\u62a5\u8868\u3002<\/p>\n<p>\u4e13\u95e8\u52a0\u5165\u4e86\u540c\u540d\u5b66\u751f\u3001\u53ea\u6709\u4e00\u4e2a\u5730\u533a\u3001\u7f3a\u6574\u4e2a\u5730\u533a\u3001\u7a7a\u8868\u4ee5\u53ca\u6253\u4e71\u63d2\u5165\u987a\u5e8f\u7684\u6570\u636e\u3002\u8fd8\u6267\u884c\u4e86\u51e0\u79cd\u80fd\u8fd0\u884c\u4f46\u903b\u8f91\u9519\u8bef\u7684SQL&#xff1a;\u6309\u59d3\u540d\u5e76\u5217\u6392\u540d\u3001\u5fd8\u8bb0\u5206\u5730\u533a\u7f16\u53f7\u3001\u6309\u5730\u533a\u800c\u4e0d\u662f\u6309\u4f4d\u7f6e\u5206\u7ec4\u3001\u628aNULL\u6539\u6210\u7a7a\u5b57\u7b26\u4e32\u3002\u6bcf\u79cd\u90fd\u8981\u627e\u5230\u5177\u4f53\u53cd\u4f8b&#xff0c;\u4e0d\u80fd\u53ea\u770b\u201c\u7a0b\u5e8f\u8dd1\u5b8c\u4e86\u201d\u3002<\/p>\n<p>\u9644\u5f55\u7684\u9a8c\u8bc1\u7a0b\u5e8f\u4f7f\u7528\u9694\u79bb\u7684MySQL 8\u6570\u636e\u76ee\u5f55&#xff0c;\u4ec5\u901a\u8fc7\u672c\u673aUnix socket\u8fde\u63a5&#xff0c;\u7ed3\u675f\u540e\u5173\u95ed\u81ea\u5df1\u542f\u52a8\u7684\u8fdb\u7a0b&#xff1b;\u4e0d\u8fde\u63a5\u5df2\u6709\u6570\u636e\u5e93\u3002\u9700\u8981Python 3\u548cMySQL 8\u7684\u670d\u52a1\u7aef\u3001\u5ba2\u6237\u7aef\u53ca\u8fd0\u884c\u5e93\u3002\u9ed8\u8ba4\u8def\u5f84\u662f\u672c\u6587\u7684WSL\u5b9e\u9a8c\u73af\u5883&#xff0c;\u53ef\u901a\u8fc7BLOG_MYSQL_ROOT\u6307\u5b9a\u89e3\u5305\u76ee\u5f55&#xff1b;\u4e0d\u540c\u5b89\u88c5\u5e03\u5c40\u8fd8\u9700\u8c03\u6574\u8fd0\u884c\u5e93\u8def\u5f84\u3002<\/p>\n<p>\u4e0b\u9762JSON\u4fdd\u5b58\u4e3aarticle-steps.json&#xff0c;Python\u4fdd\u5b58\u4e3a\u540c\u76ee\u5f55\u7684verify_roster.py&#xff0c;\u8fd0\u884cpython3 verify_roster.py\u3002JSON\u4fdd\u7559\u672c\u6587\u5404\u9636\u6bb5SQL\u53ca\u793a\u4f8b\u671f\u671b\u503c&#xff0c;Python\u5148\u6838\u5bf9\u793a\u4f8b&#xff0c;\u518d\u6279\u91cf\u5bf9\u7167\u3002<\/p>\n<p>[<br \/>\n  {<br \/>\n    &#034;id&#034;: &#034;setup&#034;,<br \/>\n    &#034;sql&#034;: &#034;CREATE TABLE Student (\\\\n    student_id INT PRIMARY KEY,\\\\n    name VARCHAR(20) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,\\\\n    continent ENUM(&#039;Asia&#039;,&#039;Europe&#039;,&#039;America&#039;) NOT NULL\\\\n);\\\\nINSERT INTO Student VALUES\\\\n    (30, &#039;BO&#039;, &#039;Asia&#039;),\\\\n    (11, &#039;ADA&#039;, &#039;Europe&#039;),\\\\n    (9, &#039;AMY&#039;, &#039;Asia&#039;),\\\\n    (24, &#039;CARL&#039;, &#039;America&#039;),\\\\n    (3, &#039;AMY&#039;, &#039;Asia&#039;),\\\\n    (8, &#039;BEN&#039;, &#039;Europe&#039;);&#034;,<br \/>\n    &#034;expected&#034;: []<br \/>\n  },<br \/>\n  {<br \/>\n    &#034;id&#034;: &#034;ranked&#034;,<br \/>\n    &#034;sql&#034;: &#034;SELECT student_id, name, continent,\\\\n       ROW_NUMBER() OVER (\\\\n           PARTITION BY continent\\\\n           ORDER BY name, student_id\\\\n       ) AS pos\\\\nFROM Student\\\\nORDER BY continent, pos;&#034;,<br \/>\n    &#034;expected&#034;: [<br \/>\n      &#034;3\\\\tAMY\\\\tAsia\\\\t1&#034;,<br \/>\n      &#034;9\\\\tAMY\\\\tAsia\\\\t2&#034;,<br \/>\n      &#034;30\\\\tBO\\\\tAsia\\\\t3&#034;,<br \/>\n      &#034;11\\\\tADA\\\\tEurope\\\\t1&#034;,<br \/>\n      &#034;8\\\\tBEN\\\\tEurope\\\\t2&#034;,<br \/>\n      &#034;24\\\\tCARL\\\\tAmerica\\\\t1&#034;<br \/>\n    ]<br \/>\n  },<br \/>\n  {<br \/>\n    &#034;id&#034;: &#034;sparse&#034;,<br \/>\n    &#034;sql&#034;: &#034;WITH ranked AS (\\\\n    SELECT student_id, name, continent,\\\\n           ROW_NUMBER() OVER (\\\\n               PARTITION BY continent ORDER BY name, student_id\\\\n           ) AS pos\\\\n    FROM Student\\\\n)\\\\nSELECT pos,\\\\n       CASE WHEN continent &#061; &#039;Asia&#039; THEN name END AS Asia,\\\\n       CASE WHEN continent &#061; &#039;Europe&#039; THEN name END AS Europe,\\\\n       CASE WHEN continent &#061; &#039;America&#039; THEN name END AS America\\\\nFROM ranked\\\\nORDER BY pos, continent;&#034;,<br \/>\n    &#034;expected&#034;: [<br \/>\n      &#034;1\\\\tAMY\\\\tNULL\\\\tNULL&#034;,<br \/>\n      &#034;1\\\\tNULL\\\\tADA\\\\tNULL&#034;,<br \/>\n      &#034;1\\\\tNULL\\\\tNULL\\\\tCARL&#034;,<br \/>\n      &#034;2\\\\tAMY\\\\tNULL\\\\tNULL&#034;,<br \/>\n      &#034;2\\\\tNULL\\\\tBEN\\\\tNULL&#034;,<br \/>\n      &#034;3\\\\tBO\\\\tNULL\\\\tNULL&#034;<br \/>\n    ]<br \/>\n  },<br \/>\n  {<br \/>\n    &#034;id&#034;: &#034;final&#034;,<br \/>\n    &#034;sql&#034;: &#034;WITH ranked AS (\\\\n    SELECT name, continent,\\\\n           ROW_NUMBER() OVER (\\\\n               PARTITION BY continent ORDER BY name, student_id\\\\n           ) AS pos\\\\n    FROM Student\\\\n)\\\\nSELECT MAX(CASE WHEN continent &#061; &#039;Asia&#039; THEN name END) AS Asia,\\\\n       MAX(CASE WHEN continent &#061; &#039;Europe&#039; THEN name END) AS Europe,\\\\n       MAX(CASE WHEN continent &#061; &#039;America&#039; THEN name END) AS America\\\\nFROM ranked\\\\nGROUP BY pos\\\\nORDER BY pos;&#034;,<br \/>\n    &#034;expected&#034;: [<br \/>\n      &#034;AMY\\\\tADA\\\\tCARL&#034;,<br \/>\n      &#034;AMY\\\\tBEN\\\\tNULL&#034;,<br \/>\n      &#034;BO\\\\tNULL\\\\tNULL&#034;<br \/>\n    ]<br \/>\n  }<br \/>\n]<\/p>\n<p>import getpass<br \/>\nimport itertools<br \/>\nimport json<br \/>\nimport os<br \/>\nimport random<br \/>\nimport subprocess<br \/>\nimport tempfile<br \/>\nimport time<br \/>\nfrom datetime import date, timedelta<br \/>\nfrom pathlib import Path<\/p>\n<p>base &#061; Path(__file__).resolve().parent<br \/>\nsteps &#061; json.loads((base \/ &#039;article-steps.json&#039;).read_text())<br \/>\npackage &#061; Path(os.environ.get(&#039;BLOG_MYSQL_ROOT&#039;,<br \/>\n    &#039;\/mnt\/d\/blog-ops\/experiments\/2026-10-03-candidates\/mysql-packages\/root&#039;))<br \/>\nenv &#061; dict(os.environ, LD_LIBRARY_PATH&#061;str(package \/ &#039;usr\/lib\/x86_64-linux-gnu&#039;))<br \/>\nrun &#061; Path(tempfile.mkdtemp(prefix&#061;&#039;roster-&#039;, dir&#061;base))<br \/>\n(run \/ &#039;data&#039;).mkdir()<br \/>\nsock &#061; Path(&#039;\/dev\/shm&#039;) \/ (run.name &#043; &#039;.sock&#039;)<br \/>\nargs &#061; [str(package \/ &#039;usr\/sbin\/mysqld&#039;), &#039;&#8211;no-defaults&#039;,<br \/>\n        &#039;&#8211;basedir&#061;&#039; &#043; str(package \/ &#039;usr&#039;), &#039;&#8211;datadir&#061;&#039; &#043; str(run \/ &#039;data&#039;),<br \/>\n        &#039;&#8211;lc-messages-dir&#061;&#039; &#043; str(package \/ &#039;usr\/share\/mysql&#039;),<br \/>\n        &#039;&#8211;user&#061;&#039; &#043; getpass.getuser(), &#039;&#8211;secure-file-priv&#061;NULL&#039;,<br \/>\n        &#039;&#8211;innodb-buffer-pool-size&#061;67108864&#039;, &#039;&#8211;innodb-redo-log-capacity&#061;16777216&#039;,<br \/>\n        &#039;&#8211;log-error&#061;&#039; &#043; str(run \/ &#039;server.log&#039;)]<br \/>\ninit &#061; subprocess.run(args &#043; [&#039;&#8211;initialize-insecure&#039;], env&#061;env,<br \/>\n                      capture_output&#061;True, text&#061;True, timeout&#061;90)<br \/>\nif init.returncode:<br \/>\n    raise RuntimeError(init.stderr)<br \/>\nclient &#061; [str(package \/ &#039;usr\/bin\/mysql&#039;), &#039;&#8211;no-defaults&#039;, &#039;&#8211;protocol&#061;SOCKET&#039;,<br \/>\n          &#039;&#8211;socket&#061;&#039; &#043; str(sock), &#039;-u&#039;, &#039;root&#039;, &#039;&#8211;batch&#039;, &#039;&#8211;skip-column-names&#039;,<br \/>\n          &#039;&#8211;connect-timeout&#061;2&#039;]<br \/>\nserver &#061; subprocess.Popen(args &#043; [&#039;&#8211;skip-networking&#039;, &#039;&#8211;mysqlx&#061;0&#039;,<br \/>\n    &#039;&#8211;socket&#061;&#039; &#043; str(sock), &#039;&#8211;pid-file&#061;&#039; &#043; str(run \/ &#039;mysql.pid&#039;),<br \/>\n    &#039;&#8211;tmpdir&#061;&#039; &#043; str(run)], env&#061;env, stdout&#061;subprocess.DEVNULL,<br \/>\n    stderr&#061;subprocess.DEVNULL)<br \/>\nrecord &#061; {&#039;passed&#039;: False, &#039;run&#039;: str(run)}<\/p>\n<p>def sql(text):<br \/>\n    result &#061; subprocess.run(client, input&#061;text, env&#061;env, capture_output&#061;True,<br \/>\n                            text&#061;True, timeout&#061;120)<br \/>\n    if result.returncode or result.stderr.strip():<br \/>\n        raise RuntimeError(result.stdout &#043; result.stderr)<br \/>\n    return result.stdout.splitlines()<\/p>\n<p>def oracle(rows):<br \/>\n    lists &#061; [sorted((n, i) for i, n, c in rows if c &#061;&#061; region)<br \/>\n             for region in [&#039;Asia&#039;, &#039;Europe&#039;, &#039;America&#039;]]<br \/>\n    return [&#039;\\\\t&#039;.join(g[p][0] if p &lt; len(g) else &#039;NULL&#039; for g in lists)<br \/>\n            for p in range(max(map(len, lists), default&#061;0))]<\/p>\n<p>def insert(rows):<br \/>\n    if not rows:<br \/>\n        return &#039;&#039;<br \/>\n    return &#039;INSERT INTO Student VALUES &#039; &#043; &#039;,&#039;.join(<br \/>\n        f&#034;({i},&#039;{n}&#039;,&#039;{c}&#039;)&#034; for i, n, c in rows) &#043; &#039;;&#039;<\/p>\n<p>def chunks(lines, prefix):<br \/>\n    groups &#061; []<br \/>\n    for line in lines:<br \/>\n        if line.startswith(prefix):<br \/>\n            groups.append([])<br \/>\n        else:<br \/>\n            assert groups, line<br \/>\n            groups[-1].append(line)<br \/>\n    return groups<\/p>\n<p>try:<br \/>\n    for _ in range(200):<br \/>\n        if server.poll() is not None:<br \/>\n            raise RuntimeError((run \/ &#039;server.log&#039;).read_text())<br \/>\n        if sock.exists():<br \/>\n            try:<br \/>\n                sql(&#039;SELECT 1;&#039;)<br \/>\n                break<br \/>\n            except RuntimeError:<br \/>\n                pass<br \/>\n        time.sleep(0.1)<br \/>\n    else:<br \/>\n        raise TimeoutError(&#039;MySQL startup timed out&#039;)<br \/>\n    record[&#039;version&#039;] &#061; sql(&#039;SELECT VERSION();&#039;)[0]<br \/>\n    commands &#061; [&#039;CREATE DATABASE blog_roster; USE blog_roster;&#039;]<br \/>\n    for i, step in enumerate(steps):<br \/>\n        commands.extend([f&#034;SELECT &#039;__step_{i}__&#039;;&#034;, step[&#039;sql&#039;]])<br \/>\n    outputs &#061; chunks(sql(&#039;\\\\n&#039;.join(commands)), &#039;__step_&#039;)<br \/>\n    assert outputs &#061;&#061; [s[&#039;expected&#039;] for s in steps], outputs<br \/>\n    record[&#039;articleSteps&#039;] &#061; [dict(s, actual&#061;a) for s, a in zip(steps, outputs)]<br \/>\n    final &#061; next(s[&#039;sql&#039;] for s in steps if s[&#039;id&#039;] &#061;&#061; &#039;final&#039;)<br \/>\n    main &#061; [(30, &#039;BO&#039;, &#039;Asia&#039;), (11, &#039;ADA&#039;, &#039;Europe&#039;), (9, &#039;AMY&#039;, &#039;Asia&#039;),<br \/>\n            (24, &#039;CARL&#039;, &#039;America&#039;), (3, &#039;AMY&#039;, &#039;Asia&#039;), (8, &#039;BEN&#039;, &#039;Europe&#039;)]<br \/>\n    cases &#061; [main, [], [(1, &#039;Z&#039;, &#039;Europe&#039;)]]<br \/>\n    for states in itertools.product(range(4), repeat&#061;6):<br \/>\n        cases.append([(i&#043;1, [&#039;A&#039;,&#039;A&#039;,&#039;B&#039;,&#039;C&#039;,&#039;A&#039;,&#039;B&#039;][i], [&#039;Asia&#039;,&#039;Europe&#039;,&#039;America&#039;][v-1])<br \/>\n                      for i, v in enumerate(states) if v])<br \/>\n    rng &#061; random.Random(618)<br \/>\n    for _ in range(100):<br \/>\n        rows &#061; [(i, rng.choice([&#039;A&#039;,&#039;B&#039;,&#039;C&#039;,&#039;D&#039;]), rng.choice([&#039;Asia&#039;,&#039;Europe&#039;,&#039;America&#039;]))<br \/>\n                for i in range(1, rng.randint(1, 35))]<br \/>\n        rng.shuffle(rows)<br \/>\n        cases.append(rows)<br \/>\n    commands &#061; [&#039;USE blog_roster;&#039;]<br \/>\n    for i, rows in enumerate(cases):<br \/>\n        commands.extend([&#039;DELETE FROM Student;&#039;, insert(rows), f&#034;SELECT &#039;__case_{i}__&#039;;&#034;, final])<br \/>\n    outputs &#061; chunks(sql(&#039;\\\\n&#039;.join(commands)), &#039;__case_&#039;)<br \/>\n    assert len(outputs) &#061;&#061; len(cases)<br \/>\n    for i, (got, rows) in enumerate(zip(outputs, cases)):<br \/>\n        assert got &#061;&#061; oracle(rows), {&#039;case&#039;: i, &#039;input&#039;: rows, &#039;actual&#039;: got, &#039;expected&#039;: oracle(rows)}<br \/>\n    record[&#039;cases&#039;] &#061; len(cases)<br \/>\n    record[&#039;exhaustiveCases&#039;] &#061; 4**6<br \/>\n    record[&#039;randomSeed&#039;] &#061; 618<br \/>\n    variants &#061; {<br \/>\n        &#039;name-rank&#039;: final.replace(&#039;ROW_NUMBER()&#039;, &#039;RANK()&#039;).replace(&#039;ORDER BY name, student_id&#039;, &#039;ORDER BY name&#039;),<br \/>\n        &#039;dense-name-rank&#039;: final.replace(&#039;ROW_NUMBER()&#039;, &#039;DENSE_RANK()&#039;).replace(&#039;ORDER BY name, student_id&#039;, &#039;ORDER BY name&#039;),<br \/>\n        &#039;global-number&#039;: final.replace(&#039;PARTITION BY continent &#039;, &#039;&#039;),<br \/>\n        &#039;wrong-group&#039;: final.replace(&#039;GROUP BY pos\\\\nORDER BY pos&#039;, &#039;GROUP BY continent\\\\nORDER BY continent&#039;),<br \/>\n        &#039;empty-string&#039;: final.replace(&#039;THEN name END&#039;, &#034;THEN name ELSE &#039;&#039; END&#034;),<br \/>\n        &#039;reverse-output&#039;: final.replace(&#039;ORDER BY pos;&#039;, &#039;ORDER BY pos DESC;&#039;)<br \/>\n    }<br \/>\n    record[&#039;mutants&#039;] &#061; []<br \/>\n    for name, query in variants.items():<br \/>\n        assert query !&#061; final<br \/>\n        got &#061; sql(&#039;USE blog_roster; DELETE FROM Student;&#039; &#043; insert(main) &#043; query)<br \/>\n        assert got !&#061; oracle(main), name<br \/>\n        record[&#039;mutants&#039;].append({&#039;name&#039;: name, &#039;input&#039;: main, &#039;actual&#039;: got,<br \/>\n                                   &#039;expected&#039;: oracle(main), &#039;rejected&#039;: True})<br \/>\n    record[&#039;passed&#039;] &#061; True<br \/>\nfinally:<br \/>\n    server.terminate()<br \/>\n    try:<br \/>\n        server.wait(timeout&#061;30)<br \/>\n    except subprocess.TimeoutExpired:<br \/>\n        server.kill()<br \/>\n        server.wait(timeout&#061;5)<br \/>\n    record[&#039;serverStopped&#039;] &#061; server.poll() is not None<br \/>\n    record[&#039;socketRemoved&#039;] &#061; not sock.exists()<br \/>\n    (run \/ &#039;results.json&#039;).write_text(json.dumps(record, indent&#061;2))<br \/>\n    print(&#039;RESULTS&#061;&#039; &#043; str(run \/ &#039;results.json&#039;))<br \/>\nassert record[&#039;passed&#039;] and record[&#039;serverStopped&#039;] and record[&#039;socketRemoved&#039;]<br \/>\nprint(&#039;ROSTER_CHECKS_PASSED&#039;)<\/p>\n<p>\u53c2\u8003&#xff1a;MySQL 8\u7a97\u53e3\u51fd\u6570\u8bf4\u660e\u3002\u672c\u6587\u53ea\u9a8c\u8bc1\u8fd9\u91cc\u7ea6\u5b9a\u7684\u7ec3\u4e60&#xff0c;\u6ca1\u6709\u5728LeetCode\u63d0\u4ea4&#xff0c;\u4e5f\u6ca1\u6709\u6d4b\u8bd5\u5927\u89c4\u6a21\u540d\u5355\u7684\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e09\u4efd\u540d\u5355\u957f\u77ed\u4e0d\u540c&#xff0c;SQL\u600e\u4e48\u6a2a\u7740\u6392&#xff1f;\u5148\u7ed9\u6bcf\u7ec4\u5b66\u751f\u627e\u4e2a\u4f4d\u7f6e<br \/>\n\u5047\u8bbe\u624b\u91cc\u6709\u4e09\u4efd\u5b66\u751f\u540d\u5355&#xff0c;\u8981\u653e\u8fdb\u4e00\u5f20\u62a5\u8868\u91cc&#xff1a;\u4e9a\u6d32\u4e00\u5217&#xff0c;\u6b27\u6d32\u4e00\u5217&#xff0c;\u7f8e\u6d32\u4e00\u5217\u3002\u6bcf\u5217\u6309\u59d3\u540d\u6392\u5e8f&#xff0c;\u54ea\u4efd\u540d\u5355\u5148\u6392\u5b8c&#xff0c;\u540e\u9762\u7684\u683c\u5b50\u5c31\u7559\u7a7a\u3002<br \/>\n\u8fd9\u542c\u8d77\u6765\u4e0d\u590d\u6742&#xff0c;\u590d\u5236\u5230\u8868\u683c\u91cc\u5c31\u80fd\u6446\u51fa\u6765\u3002\u4f46\u5728\u6570\u636e\u5e93\u91cc&#xff0c;\u5b66\u751f\u539f\u672c\u662f\u4e00\u884c\u4e00\u884c\u5b58\u7684\u3002\u6211\u4eec\u5148\u4e0d\u8981\u627e\u201c\u884c\u8f6c\u5217\u6a21\u677f\u201d&#xff0c;\u770b\u6e05\u695a\u8981\u600e\u6837\u6446\u3002<br \/>\n\u4e0b\u9762\u8fd9\u9053\u7ec3\u4e60\u6765<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[114,768,100],"topic":[],"class_list":["post-121615","post","type-post","status-publish","format-standard","hentry","category-server","tag-mysql","tag-sql","tag-100"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4e09\u4efd\u540d\u5355\u957f\u77ed\u4e0d\u540c\uff0cSQL\u600e\u4e48\u6a2a\u7740\u6392\uff1f\u5148\u7ed9\u6bcf\u7ec4\u5b66\u751f\u627e\u4e2a\u4f4d\u7f6e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/121615.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4e09\u4efd\u540d\u5355\u957f\u77ed\u4e0d\u540c\uff0cSQL\u600e\u4e48\u6a2a\u7740\u6392\uff1f\u5148\u7ed9\u6bcf\u7ec4\u5b66\u751f\u627e\u4e2a\u4f4d\u7f6e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e09\u4efd\u540d\u5355\u957f\u77ed\u4e0d\u540c&#xff0c;SQL\u600e\u4e48\u6a2a\u7740\u6392&#xff1f;\u5148\u7ed9\u6bcf\u7ec4\u5b66\u751f\u627e\u4e2a\u4f4d\u7f6e \u5047\u8bbe\u624b\u91cc\u6709\u4e09\u4efd\u5b66\u751f\u540d\u5355&#xff0c;\u8981\u653e\u8fdb\u4e00\u5f20\u62a5\u8868\u91cc&#xff1a;\u4e9a\u6d32\u4e00\u5217&#xff0c;\u6b27\u6d32\u4e00\u5217&#xff0c;\u7f8e\u6d32\u4e00\u5217\u3002\u6bcf\u5217\u6309\u59d3\u540d\u6392\u5e8f&#xff0c;\u54ea\u4efd\u540d\u5355\u5148\u6392\u5b8c&#xff0c;\u540e\u9762\u7684\u683c\u5b50\u5c31\u7559\u7a7a\u3002 \u8fd9\u542c\u8d77\u6765\u4e0d\u590d\u6742&#xff0c;\u590d\u5236\u5230\u8868\u683c\u91cc\u5c31\u80fd\u6446\u51fa\u6765\u3002\u4f46\u5728\u6570\u636e\u5e93\u91cc&#xff0c;\u5b66\u751f\u539f\u672c\u662f\u4e00\u884c\u4e00\u884c\u5b58\u7684\u3002\u6211\u4eec\u5148\u4e0d\u8981\u627e\u201c\u884c\u8f6c\u5217\u6a21\u677f\u201d&#xff0c;\u770b\u6e05\u695a\u8981\u600e\u6837\u6446\u3002 \u4e0b\u9762\u8fd9\u9053\u7ec3\u4e60\u6765\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/121615.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-02T21:08:35+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/121615.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/121615.html\",\"name\":\"\u4e09\u4efd\u540d\u5355\u957f\u77ed\u4e0d\u540c\uff0cSQL\u600e\u4e48\u6a2a\u7740\u6392\uff1f\u5148\u7ed9\u6bcf\u7ec4\u5b66\u751f\u627e\u4e2a\u4f4d\u7f6e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-11-02T21:08:35+00:00\",\"dateModified\":\"2026-11-02T21:08:35+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/121615.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/121615.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/121615.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4e09\u4efd\u540d\u5355\u957f\u77ed\u4e0d\u540c\uff0cSQL\u600e\u4e48\u6a2a\u7740\u6392\uff1f\u5148\u7ed9\u6bcf\u7ec4\u5b66\u751f\u627e\u4e2a\u4f4d\u7f6e\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4e09\u4efd\u540d\u5355\u957f\u77ed\u4e0d\u540c\uff0cSQL\u600e\u4e48\u6a2a\u7740\u6392\uff1f\u5148\u7ed9\u6bcf\u7ec4\u5b66\u751f\u627e\u4e2a\u4f4d\u7f6e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/121615.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4e09\u4efd\u540d\u5355\u957f\u77ed\u4e0d\u540c\uff0cSQL\u600e\u4e48\u6a2a\u7740\u6392\uff1f\u5148\u7ed9\u6bcf\u7ec4\u5b66\u751f\u627e\u4e2a\u4f4d\u7f6e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e09\u4efd\u540d\u5355\u957f\u77ed\u4e0d\u540c&#xff0c;SQL\u600e\u4e48\u6a2a\u7740\u6392&#xff1f;\u5148\u7ed9\u6bcf\u7ec4\u5b66\u751f\u627e\u4e2a\u4f4d\u7f6e \u5047\u8bbe\u624b\u91cc\u6709\u4e09\u4efd\u5b66\u751f\u540d\u5355&#xff0c;\u8981\u653e\u8fdb\u4e00\u5f20\u62a5\u8868\u91cc&#xff1a;\u4e9a\u6d32\u4e00\u5217&#xff0c;\u6b27\u6d32\u4e00\u5217&#xff0c;\u7f8e\u6d32\u4e00\u5217\u3002\u6bcf\u5217\u6309\u59d3\u540d\u6392\u5e8f&#xff0c;\u54ea\u4efd\u540d\u5355\u5148\u6392\u5b8c&#xff0c;\u540e\u9762\u7684\u683c\u5b50\u5c31\u7559\u7a7a\u3002 \u8fd9\u542c\u8d77\u6765\u4e0d\u590d\u6742&#xff0c;\u590d\u5236\u5230\u8868\u683c\u91cc\u5c31\u80fd\u6446\u51fa\u6765\u3002\u4f46\u5728\u6570\u636e\u5e93\u91cc&#xff0c;\u5b66\u751f\u539f\u672c\u662f\u4e00\u884c\u4e00\u884c\u5b58\u7684\u3002\u6211\u4eec\u5148\u4e0d\u8981\u627e\u201c\u884c\u8f6c\u5217\u6a21\u677f\u201d&#xff0c;\u770b\u6e05\u695a\u8981\u600e\u6837\u6446\u3002 \u4e0b\u9762\u8fd9\u9053\u7ec3\u4e60\u6765","og_url":"https:\/\/www.wsisp.com\/helps\/121615.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-11-02T21:08:35+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/121615.html","url":"https:\/\/www.wsisp.com\/helps\/121615.html","name":"\u4e09\u4efd\u540d\u5355\u957f\u77ed\u4e0d\u540c\uff0cSQL\u600e\u4e48\u6a2a\u7740\u6392\uff1f\u5148\u7ed9\u6bcf\u7ec4\u5b66\u751f\u627e\u4e2a\u4f4d\u7f6e - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-11-02T21:08:35+00:00","dateModified":"2026-11-02T21:08:35+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/121615.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/121615.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/121615.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4e09\u4efd\u540d\u5355\u957f\u77ed\u4e0d\u540c\uff0cSQL\u600e\u4e48\u6a2a\u7740\u6392\uff1f\u5148\u7ed9\u6bcf\u7ec4\u5b66\u751f\u627e\u4e2a\u4f4d\u7f6e"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/121615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=121615"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/121615\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=121615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=121615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=121615"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=121615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}