{"id":77592,"date":"2026-02-24T23:34:02","date_gmt":"2026-02-24T15:34:02","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/77592.html"},"modified":"2026-02-24T23:34:02","modified_gmt":"2026-02-24T15:34:02","slug":"%e9%9b%b6%e5%9f%ba%e7%a1%80sql%e5%bf%ab%e9%80%9f%e5%85%a5%e9%97%a8_%e7%89%9b%e5%ae%a2%e5%88%b7%e9%a2%98%e6%8c%87%e5%8d%972629-%e6%89%8b%e6%8a%8a%e6%89%8b%e5%b8%a6%e5%88%b7%e5%bf%85%e4%bc%9a%e7%9a%84","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/77592.html","title":{"rendered":"\u96f6\u57fa\u7840SQL\u5feb\u901f\u5165\u95e8_\u725b\u5ba2\u5237\u9898\u6307\u5357:26~29 \u624b\u628a\u624b\u5e26\u5237\u5fc5\u4f1a\u7684\u5e38\u7528\u51fd\u6570,\u6761\u4ef6\u51fd\u6570,\u65e5\u671f\u51fd\u6570"},"content":{"rendered":"<h2>\u5fc5\u4f1a\u7684\u5e38\u7528\u51fd\u6570<\/h2>\n<h3>\u6761\u4ef6\u51fd\u6570<\/h3>\n<h4>1.\u00a0<span style=\"color:#4da8ee\">IF<\/span>\u00a0\u51fd\u6570<\/h4>\n<p>IF\u00a0\u51fd\u6570\u7528\u4e8e\u6839\u636e\u6761\u4ef6\u8fd4\u56de\u4e24\u4e2a\u503c\u4e2d\u7684\u4e00\u4e2a\u3002\u5b83\u7c7b\u4f3c\u4e8e\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u00a0<span style=\"background-color:#38d8f0\">if-else<\/span>\u00a0\u8bed\u53e5<\/p>\n<h5>\u8bed\u6cd5&#xff1a;<\/h5>\n<p>IF(condition, true_value, false_value)<\/p>\n<ul>\n<li>condition&#xff1a;\u6761\u4ef6<\/li>\n<li>true_value&#xff1a;\u5982\u679c\u6761\u4ef6\u4e3a\u00a0TRUE&#xff0c;\u5219\u8fd4\u56de\u7684\u503c\u3002<\/li>\n<li>false_value&#xff1a;\u5982\u679c\u6761\u4ef6\u4e3a\u00a0FALSE&#xff0c;\u5219\u8fd4\u56de\u7684\u503c\u3002<\/li>\n<\/ul>\n<h4>2.\u00a0<span style=\"color:#4da8ee\">CASE<\/span>\u00a0\u8bed\u53e5<\/h4>\n<p>CASE\u00a0\u8bed\u53e5\u7528\u4e8e\u6839\u636e\u591a\u4e2a\u6761\u4ef6\u8fd4\u56de\u4e0d\u540c\u7684\u503c\u3002\u5b83\u7c7b\u4f3c\u4e8e\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u00a0switch-case\u00a0\u8bed\u53e5<\/p>\n<h5>\u8bed\u6cd5&#xff1a;<\/h5>\n<p>CASE<br \/>\n    WHEN condition1 THEN result1<br \/>\n    WHEN condition2 THEN result2<br \/>\n    &#8230;<br \/>\n    ELSE default_result<br \/>\nEND<\/p>\n<h4>3.\u00a0<span style=\"color:#4da8ee\">COALESCE\u00a0<\/span>\u51fd\u6570<\/h4>\n<p>COALESCE\u00a0\u51fd\u6570\u7528\u4e8e\u8fd4\u56de\u53c2\u6570\u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a\u975e\u00a0NULL\u00a0\u503c\u3002\u5982\u679c\u6ca1\u6709\u975e\u00a0NULL\u00a0\u503c&#xff0c;\u5219\u8fd4\u56de\u00a0NULL<\/p>\n<h5>\u8bed\u6cd5&#xff1a;<\/h5>\n<p>COALESCE(value1, value2, &#8230;)<\/p>\n<h4>4.\u00a0<span style=\"color:#4da8ee\">NULLIF<\/span>\u00a0\u51fd\u6570<\/h4>\n<p>NULLIF\u00a0\u51fd\u6570\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u503c&#xff0c;\u5982\u679c\u5b83\u4eec\u76f8\u7b49&#xff0c;\u5219\u8fd4\u56de\u00a0NULL&#xff0c;\u5426\u5219\u8fd4\u56de\u7b2c\u4e00\u4e2a\u503c<\/p>\n<h5>\u8bed\u6cd5&#xff1a;<\/h5>\n<p>NULLIF(value1, value2)<\/p>\n<h4>5.\u00a0<span style=\"color:#4da8ee\">IFNULL\u00a0<\/span>\u51fd\u6570<\/h4>\n<p>IFNULL\u00a0\u7528\u4e8e\u68c0\u67e5\u4e00\u4e2a\u503c\u662f\u5426\u4e3a\u00a0NULL&#xff0c;\u5982\u679c\u662f\u00a0NULL&#xff0c;\u5219\u8fd4\u56de\u4e00\u4e2a\u6307\u5b9a\u7684\u9ed8\u8ba4\u503c<\/p>\n<h5>\u8bed\u6cd5:<\/h5>\n<p>IFNULL(expression, default_value)<\/p>\n<ul>\n<li>expression&#xff1a;\u8981\u68c0\u67e5\u7684\u8868\u8fbe\u5f0f\u3002<\/li>\n<li>default_value&#xff1a;\u5982\u679c\u00a0expression\u00a0\u4e3a\u00a0NULL&#xff0c;\u5219\u8fd4\u56de\u7684\u9ed8\u8ba4\u503c\u3002<\/li>\n<\/ul>\n<h5>\u4e0e\u5176\u4ed6\u51fd\u6570\u7684\u6bd4\u8f83<\/h5>\n<ul>\n<li>\n<p><span style=\"color:#4da8ee\">COALESCE<\/span>&#xff1a;<\/p>\n<ul>\n<li>COALESCE\u00a0\u51fd\u6570\u53ef\u4ee5\u63a5\u53d7\u591a\u4e2a\u53c2\u6570&#xff0c;\u5e76\u8fd4\u56de\u7b2c\u4e00\u4e2a\u975e\u00a0NULL\u00a0\u7684\u503c\u3002<\/li>\n<li>\u5982\u679c\u6240\u6709\u53c2\u6570\u90fd\u662f\u00a0NULL&#xff0c;\u5219\u8fd4\u56de\u00a0NULL\u3002<\/li>\n<li>\u8bed\u6cd5&#xff1a;COALESCE(value1, value2, &#8230;)\u3002<\/li>\n<li>\u793a\u4f8b&#xff1a;COALESCE(salary, 0, &#039;Not Available&#039;)\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p><span style=\"color:#4da8ee\">IF<\/span>&#xff1a;<\/p>\n<ul>\n<li>IF\u00a0\u51fd\u6570\u7528\u4e8e\u6839\u636e\u6761\u4ef6\u8fd4\u56de\u4e24\u4e2a\u503c\u4e2d\u7684\u4e00\u4e2a\u3002<\/li>\n<li>\u8bed\u6cd5&#xff1a;IF(condition, true_value, false_value)\u3002<\/li>\n<li>\u793a\u4f8b&#xff1a;IF(salary IS NULL, 0, salary)\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>\u793a\u4f8b&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"177\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153359-699dc4e7761c1.png\" width=\"320\" \/><\/h4>\n<h5>IF\u00a0\u51fd\u6570<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"392\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153359-699dc4e78ba0d.png\" width=\"511\" \/><\/h5>\n<h5>CASE\u8bed\u53e5<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"342\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153359-699dc4e7a4d38.png\" width=\"592\" \/><\/h5>\n<h5>NULLIF\u51fd\u6570<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"371\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153359-699dc4e7cf9e5.png\" width=\"379\" \/><\/h5>\n<h5>COALESCE\u00a0\u51fd\u6570<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"559\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153359-699dc4e7e72ff.png\" width=\"378\" \/><\/h5>\n<h5>IFNULL\u00a0\u51fd\u6570<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"377\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153400-699dc4e80a0b2.png\" width=\"459\" \/><\/h5>\n<h4>SQL26\u00a0\u8ba1\u7b9725\u5c81\u4ee5\u4e0a\u548c\u4ee5\u4e0b\u7684\u7528\u6237\u6570\u91cf<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"749\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153400-699dc4e821757.png\" width=\"799\" \/><\/p>\n<h5><span style=\"color:#4da8ee\">case<\/span><\/h5>\n<p>select<br \/>\n    case<br \/>\n        when age&gt;&#061;25 then &#039;25\u5c81\u53ca\u4ee5\u4e0a&#039;<br \/>\n        else &#039;25\u5c81\u4ee5\u4e0b&#039;<br \/>\n    end age_cut,<br \/>\n    count(*) number<br \/>\nfrom user_profile<br \/>\ngroup by age_cut;<\/p>\n<p>&#8212; \u9009\u62e9\u5e76\u5212\u5206\u5e74\u9f84\u6bb5&#xff0c;\u7edf\u8ba1\u6bcf\u4e2a\u5e74\u9f84\u6bb5\u7684\u7528\u6237\u6570\u91cf<br \/>\nSELECT<br \/>\n    CASE<br \/>\n        WHEN age &lt; 25 OR age IS NULL THEN &#039;25\u5c81\u4ee5\u4e0b&#039;<br \/>\n        ELSE &#039;25\u5c81\u53ca\u4ee5\u4e0a&#039;<br \/>\n    END AS age_cut,<br \/>\n    COUNT(*) AS number<br \/>\nFROM<br \/>\n    user_profile<br \/>\nGROUP BY<br \/>\n    age_cut<br \/>\nORDER BY<br \/>\n    CASE<br \/>\n        WHEN age_cut &#061; &#039;25\u5c81\u4ee5\u4e0b&#039; THEN 1<br \/>\n        ELSE 2<br \/>\n    END;<\/p>\n<h6>\u4ee3\u7801\u89e3\u91ca<\/h6>\n<\/p>\n<ul>\n<li>\n<p>SELECT\u00a0\u5b50\u53e5&#xff1a;<\/p>\n<ul>\n<li>\u4f7f\u7528\u00a0CASE WHEN\u00a0\u8bed\u53e5\u6765\u5224\u65ad\u00a0age\u00a0\u5b57\u6bb5&#xff1a;\n<ul>\n<li>\u5982\u679c\u00a0age\u00a0\u5c0f\u4e8e25\u5c81\u6216\u4e3a\u00a0NULL&#xff0c;\u5219\u5c06\u5176\u5f52\u7c7b\u4e3a\u00a0&#039;25\u5c81\u4ee5\u4e0b&#039;\u3002<\/li>\n<li>\u5426\u5219&#xff0c;\u5f52\u7c7b\u4e3a\u00a0&#039;25\u5c81\u53ca\u4ee5\u4e0a&#039;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u4e3a\u5212\u5206\u540e\u7684\u7ed3\u679c\u547d\u540d\u4e3a\u00a0age_cut\u3002<\/li>\n<li>\u4f7f\u7528\u00a0COUNT(*)\u00a0\u7edf\u8ba1\u6bcf\u4e2a\u5e74\u9f84\u6bb5\u7684\u7528\u6237\u6570\u91cf&#xff0c;\u5e76\u547d\u540d\u4e3a\u00a0number\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>FROM\u00a0\u5b50\u53e5&#xff1a;<\/p>\n<ul>\n<li>\u6307\u5b9a\u6570\u636e\u6765\u6e90\u4e3a\u00a0user_profile\u00a0\u8868\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>GROUP BY\u00a0\u5b50\u53e5&#xff1a;<\/p>\n<ul>\n<li>\u6309\u7167\u5212\u5206\u540e\u7684\u00a0age_cut\u00a0\u8fdb\u884c\u5206\u7ec4&#xff0c;\u4ee5\u4fbf\u7edf\u8ba1\u6bcf\u4e2a\u7ec4\u7684\u7528\u6237\u6570\u91cf\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>ORDER BY\u00a0\u5b50\u53e5&#xff1a;<\/p>\n<ul>\n<li>\u6839\u636e\u9700\u6c42&#xff0c;\u5c06\u00a0&#039;25\u5c81\u4ee5\u4e0b&#039;\u00a0\u7684\u7ed3\u679c\u6392\u5728\u524d\u9762&#xff0c;&#039;25\u5c81\u53ca\u4ee5\u4e0a&#039;\u00a0\u7684\u7ed3\u679c\u6392\u5728\u540e\u9762\u3002<\/li>\n<li>\u901a\u8fc7\u00a0CASE WHEN\u00a0\u8bed\u53e5\u5b9e\u73b0\u81ea\u5b9a\u4e49\u6392\u5e8f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5><span style=\"color:#4da8ee\">if<\/span><\/h5>\n<p>select<br \/>\n    if(age&lt;25 or age is null,&#039;25\u5c81\u4ee5\u4e0b&#039;,&#039;25\u5c81\u53ca\u4ee5\u4e0a&#039;) age_cut,<br \/>\n    count(*) number<br \/>\nfrom user_profile<br \/>\ngroup by age_cut;<\/p>\n<h5><span style=\"color:#4da8ee\">UNION ALL<\/span>\u5e76\u96c6\u663e\u793a(\u4e0d\u63a8\u8350)<\/h5>\n<p>select &#039;25\u5c81\u53ca\u4ee5\u4e0a&#039;,count(id) number<br \/>\nfrom user_profile<br \/>\nwhere age&gt;&#061;25<br \/>\nunion all<br \/>\nselect &#039;25\u5c81\u4ee5\u4e0b&#039;,count(id) number<br \/>\nfrom user_profile<br \/>\nwhere age&lt;25 or age is null<br \/>\norder by number desc;<\/p>\n<p>SELECT &#034;25\u5c81\u4ee5\u4e0b&#034; as age_cut,count(device_id)<br \/>\nFROM user_profile<br \/>\nWHERE age&lt;25 OR age IS null<br \/>\nUNION ALL<br \/>\nSELECT &#034;25\u5c81\u53ca\u4ee5\u4e0a&#034; as age_cut,count(device_id)<br \/>\nFROM user_profile<br \/>\nWHERE age&gt;&#061;25<\/p>\n<h4>SQL27\u00a0\u67e5\u770b\u4e0d\u540c\u5e74\u9f84\u6bb5\u7684\u7528\u6237\u660e\u7ec6<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"709\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153400-699dc4e85ae5e.png\" width=\"783\" \/><\/h4>\n<p>select device_id,gender,<br \/>\n    case<br \/>\n        when age&lt;20 then &#039;20\u5c81\u4ee5\u4e0b&#039;<br \/>\n        when age&gt;&#061;20 and age&lt;&#061;24 then &#039;20-24\u5c81&#039;<br \/>\n        when age&gt;&#061;25 then &#039;25\u5c81\u53ca\u4ee5\u4e0a&#039;<br \/>\n        else &#039;\u5176\u4ed6&#039;<br \/>\n        end age_cut<br \/>\nfrom user_profile;<\/p>\n<h3>\u65e5\u671f\u51fd\u6570<\/h3>\n<h4>1. \u83b7\u53d6\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4<\/h4>\n<ul>\n<li>NOW()&#xff1a;\u8fd4\u56de\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4\u3002<\/li>\n<li>CURDATE()&#xff1a;\u8fd4\u56de\u5f53\u524d\u65e5\u671f\u3002<\/li>\n<li>CURTIME()&#xff1a;\u8fd4\u56de\u5f53\u524d\u65f6\u95f4\u3002<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"163\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153400-699dc4e8912c8.png\" width=\"632\" \/><\/li>\n<\/ul>\n<h4>2. \u63d0\u53d6\u65e5\u671f\u90e8\u5206<\/h4>\n<ul>\n<li>YEAR(date)&#xff1a;\u63d0\u53d6\u65e5\u671f\u7684\u5e74\u4efd\u90e8\u5206\u3002<\/li>\n<li>MONTH(date)&#xff1a;\u63d0\u53d6\u65e5\u671f\u7684\u6708\u4efd\u90e8\u5206\u3002<\/li>\n<li>DAY(date)&#xff1a;\u63d0\u53d6\u65e5\u671f\u7684\u65e5\u90e8\u5206\u3002<\/li>\n<li>HOUR(time)&#xff1a;\u63d0\u53d6\u65f6\u95f4\u7684\u5c0f\u65f6\u90e8\u5206\u3002<\/li>\n<li>MINUTE(time)&#xff1a;\u63d0\u53d6\u65f6\u95f4\u7684\u5206\u949f\u90e8\u5206\u3002<\/li>\n<li>SECOND(time)&#xff1a;\u63d0\u53d6\u65f6\u95f4\u7684\u79d2\u90e8\u5206\u3002<\/li>\n<\/ul>\n<h4>3. \u65e5\u671f\u8ba1\u7b97<\/h4>\n<ul>\n<li>DATE_ADD(date, INTERVAL expr type)&#xff1a;\u5728\u65e5\u671f\u4e0a\u52a0\u4e0a\u4e00\u4e2a\u65f6\u95f4\u95f4\u9694\u3002<\/li>\n<li>DATE_SUB(date, INTERVAL expr type)&#xff1a;\u4ece\u65e5\u671f\u4e2d\u51cf\u53bb\u4e00\u4e2a\u65f6\u95f4\u95f4\u9694\u3002<\/li>\n<li>DATEDIFF(date1, date2)&#xff1a;\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u7684\u5929\u6570\u5dee\u3002<\/li>\n<\/ul>\n<h4>4. \u683c\u5f0f\u5316\u65e5\u671f<\/h4>\n<ul>\n<li>DATE_FORMAT(date, format)&#xff1a;\u5c06\u65e5\u671f\u683c\u5f0f\u5316\u4e3a\u6307\u5b9a\u7684\u683c\u5f0f\u3002<\/li>\n<\/ul>\n<h4>5. \u5176\u4ed6\u65e5\u671f\u51fd\u6570<\/h4>\n<ul>\n<li>DAYOFWEEK(date)&#xff1a;\u8fd4\u56de\u65e5\u671f\u662f\u661f\u671f\u51e0&#xff08;1 &#061; \u661f\u671f\u5929&#xff0c;2 &#061; \u661f\u671f\u4e00&#xff0c;&#8230;&#xff0c;7 &#061; \u661f\u671f\u516d&#xff09;\u3002<\/li>\n<li>DAYOFYEAR(date)&#xff1a;\u8fd4\u56de\u65e5\u671f\u662f\u4e00\u5e74\u4e2d\u7684\u7b2c\u51e0\u5929\u3002<\/li>\n<li>WEEK(date)&#xff1a;\u8fd4\u56de\u65e5\u671f\u662f\u4e00\u5e74\u4e2d\u7684\u7b2c\u51e0\u5468\u3002<\/li>\n<li>LAST_DAY(date)&#xff1a;\u8fd4\u56de\u6307\u5b9a\u65e5\u671f\u6240\u5728\u6708\u4efd\u7684\u6700\u540e\u4e00\u5929\u3002<\/li>\n<\/ul>\n<h4>\u793a\u4f8b<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"166\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153400-699dc4e8a78cb.png\" width=\"317\" \/><\/h4>\n<h5>\u63d0\u53d6\u65e5\u671f\u90e8\u5206<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"397\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153400-699dc4e8c7201.png\" width=\"522\" \/><\/h5>\n<h5>\u65e5\u671f\u8ba1\u7b97<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"355\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153400-699dc4e8ea508.png\" width=\"471\" \/><\/h5>\n<h5>\u683c\u5f0f\u5316\u65e5\u671f<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"337\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153401-699dc4e910336.png\" width=\"441\" \/><\/h5>\n<h5>\u5176\u4ed6\u65e5\u671f\u51fd\u6570<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"375\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153401-699dc4e926f71.png\" width=\"469\" \/><\/h5>\n<h4>SQL28\u00a0\u8ba1\u7b97\u7528\u62378\u6708\u6bcf\u5929\u7684\u7ec3\u9898\u6570\u91cf<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"859\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153401-699dc4e93f3b9.png\" width=\"475\" \/><\/h4>\n<h5>\u65e5\u671f\u51fd\u6570<\/h5>\n<p>select day(date) day,<br \/>\ncount(question_id) question_cnt<br \/>\nfrom question_practice_detail<br \/>\nwhere month(date)&#061;&#039;08&#039;<br \/>\ngroup by day;<\/p>\n<p>\u6ce8\u610f\u662f<span style=\"color:#fe2c24\">&#039;08&#039;<\/span><\/p>\n<ul>\n<li>\u786e\u4fdd\u65e5\u671f\u7684\u8303\u56f4\u4ec5\u9650\u4e8e\u00a02021\u5e748\u6708&#xff0c;\u907f\u514d\u5305\u542b\u5176\u4ed6\u6708\u4efd\u7684\u6570\u636e<\/li>\n<li>\u4f7f\u7528\u00a0GROUP BY\u00a0\u8fdb\u884c\u5206\u7ec4\u7edf\u8ba1\u65f6&#xff0c;\u9700\u8981\u57fa\u4e8e\u63d0\u53d6\u7684\u00a0day<\/li>\n<\/ul>\n<h5><span style=\"color:#4da8ee\">like<\/span>\u6a21\u7cca\u67e5\u8be2<\/h5>\n<p>select day(date) day,<br \/>\ncount(question_id) question_cnt<br \/>\nfrom question_practice_detail<br \/>\nwhere date like &#039;%2021-08%&#039;<br \/>\ngroup by day;<\/p>\n<h4>SQL29\u00a0\u8ba1\u7b97\u7528\u6237\u7684\u5e73\u5747\u6b21\u65e5\u7559\u5b58\u7387<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"740\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153401-699dc4e959ca8.png\" width=\"533\" \/><\/h4>\n<p>select<br \/>\n    round(sum(case<br \/>\n            when t2.device_id is not null then 1<br \/>\n            else 0<br \/>\n            end)\/count(*),4) avg_ret<br \/>\nfrom (<br \/>\n    select distinct device_id,date<br \/>\n    from question_practice_detail<br \/>\n)t1<br \/>\nleft join<br \/>\n(<br \/>\n    select distinct device_id,date<br \/>\n    from question_practice_detail<br \/>\n)t2<br \/>\non t1.device_id&#061;t2.device_id<br \/>\nand t2.date&#061;DATE_ADD(t1.date,INTERVAL 1 day);<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"79\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153401-699dc4e98a19f.png\" width=\"444\" \/><\/p>\n<h5>\u4ee3\u7801\u89e3\u91ca<\/h5>\n<p>t2.date&#061;DATE_ADD(t1.date,INTERVAL 1 day)\u76f8\u5dee\u4e00\u5929\u00a0 \u00a0<span style=\"color:#fe2c24\"> t2.date&#061;t1.date&#043;1\u5929<\/span><\/p>\n<ul>\n<li>\n<p>\u5b50\u67e5\u8be2\u00a0p1\u00a0\u548c\u00a0p2&#xff1a;<\/p>\n<ul>\n<li>p1&#xff1a;\u63d0\u53d6\u6bcf\u4e2a\u7528\u6237\u6bcf\u5929\u7684\u552f\u4e00\u5237\u9898\u8bb0\u5f55\u3002<\/li>\n<li>p2&#xff1a;\u540c\u6837\u63d0\u53d6\u6bcf\u4e2a\u7528\u6237\u6bcf\u5929\u7684\u552f\u4e00\u5237\u9898\u8bb0\u5f55&#xff0c;\u7528\u4e8e\u4e0e\u00a0p1\u00a0\u8fdb\u884c\u81ea\u8fde\u63a5\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><span style=\"color:#4da8ee\">LEFT JOIN<\/span>\u00a0\u8fde\u63a5\u6761\u4ef6&#xff1a;<\/p>\n<ul>\n<li>\u8fde\u63a5\u6761\u4ef6\u4e3a\u540c\u4e00\u00a0device_id\u00a0\u4e14\u00a0p2.date\u00a0\u662f\u00a0p1.date\u00a0\u7684\u6b21\u65e5&#xff08;\u5373\u00a0p1.date\u00a0\u52a0\u4e00\u5929&#xff09;\u3002<\/li>\n<li>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f&#xff0c;\u53ef\u4ee5\u5224\u65ad\u7528\u6237\u5728\u67d0\u5929\u5237\u9898\u540e\u6b21\u65e5\u662f\u5426\u6709\u5237\u9898\u8bb0\u5f55\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><span style=\"color:#4da8ee\">SUM<\/span>(CASE WHEN p2.device_id IS NOT NULL THEN 1 ELSE 0 END)&#xff1a;<\/p>\n<ul>\n<li>\u7edf\u8ba1\u6709\u6b21\u65e5\u5237\u9898\u8bb0\u5f55\u7684\u7528\u6237\u6570\u91cf\u3002\u5982\u679c\u00a0p2.device_id\u00a0\u4e0d\u4e3a\u7a7a&#xff0c;\u8bf4\u660e\u7528\u6237\u5728\u6b21\u65e5\u6709\u5237\u9898\u884c\u4e3a&#xff0c;\u8ba1\u6570\u52a01\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><span style=\"color:#4da8ee\">COUNT<\/span>(*)&#xff1a;<\/p>\n<ul>\n<li>\u7edf\u8ba1\u603b\u7684\u5237\u9898\u8bb0\u5f55\u6570&#xff0c;\u5373\u603b\u7684\u00a0(device_id, date)\u00a0\u7ec4\u5408\u6570\u91cf\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><span style=\"color:#4da8ee\">ROUND<\/span>(&#8230;, 4)&#xff1a;<\/p>\n<ul>\n<li>\u5c06\u7559\u5b58\u7387\u7ed3\u679c\u4fdd\u7559\u56db\u4f4d\u5c0f\u6570\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>SQL \u5fc5\u5907\u5e38\u7528\u51fd\u6570\u6c47\u603b<\/h2>\n<table>\n<tr>\n<p>\u51fd\u6570\u5206\u7c7b<\/p>\n<p>\u51fd\u6570\u540d<\/p>\n<p>\u529f\u80fd\u8bf4\u660e<\/p>\n<p>\u793a\u4f8b<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u5b57\u7b26\u4e32\u51fd\u6570<\/p>\n<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">CONCAT(s1,s2,&#8230;)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u62fc\u63a5\u591a\u4e2a\u5b57\u7b26\u4e32<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>CONCAT(&#039;Hello&#039;, &#039; &#039;, &#039;SQL&#039;) \u2192 Hello SQL<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">SUBSTRING(s,start,len)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u622a\u53d6\u5b50\u4e32&#xff08;start\u4ece1\u5f00\u59cb&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>SUBSTRING(&#039;abcde&#039;,2,3) \u2192 bcd<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">LENGTH(s)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6&#xff08;\u5b57\u8282\u6570&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>LENGTH(&#039;SQL&#039;) \u2192 3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">UPPER(s) \/ LOWER(s)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u5b57\u7b26\u4e32\u8f6c\u5927\u5199\/\u5c0f\u5199<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>UPPER(&#039;sql&#039;) \u2192 SQL<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">TRIM(s)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u53bb\u9664\u5b57\u7b26\u4e32\u9996\u5c3e\u7a7a\u683c<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>TRIM(&#039; SQL &#039;) \u2192 SQL<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u6570\u503c\u51fd\u6570<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">ABS(n)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u53d6\u7edd\u5bf9\u503c<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>ABS(-10) \u2192 10<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">ROUND(n,d)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u56db\u820d\u4e94\u5165\u5230d\u4f4d\u5c0f\u6570<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>ROUND(3.1415,2) \u2192 3.14<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">FLOOR(n)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u5411\u4e0b\u53d6\u6574<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>FLOOR(3.9) \u2192 3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">CEIL(n)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u5411\u4e0a\u53d6\u6574<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>CEIL(3.1) \u2192 4<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">MOD(n,m)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u53d6\u6a21&#xff08;\u6c42\u4f59\u6570&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>MOD(10,3) \u2192 1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u65e5\u671f\u51fd\u6570<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">NOW()<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u83b7\u53d6\u5f53\u524d\u65e5\u671f&#043;\u65f6\u95f4<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>NOW() \u2192 2026-02-21 14:30:00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">CURDATE()<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u83b7\u53d6\u5f53\u524d\u65e5\u671f<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>CURDATE() \u2192 2026-02-21<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">DATE_ADD(date, INTERVAL expr type)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u65e5\u671f\u52a0\u51cf&#xff08;type&#xff1a;DAY\/MONTH\/YEAR&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>DATE_ADD(CURDATE(), INTERVAL 7 DAY) \u2192 \u4e00\u5468\u540e\u65e5\u671f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">DATEDIFF(date1,date2)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u7684\u5929\u6570\u5dee<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>DATEDIFF(&#039;2026-02-21&#039;,&#039;2026-02-14&#039;) \u2192 7<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">DATE_FORMAT(date,format)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u65e5\u671f\u683c\u5f0f\u5316&#xff08;format&#xff1a;%Y-%m-%d&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>DATE_FORMAT(NOW(),&#039;%Y-%m-%d&#039;) \u2192 2026-02-21<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u805a\u5408\u51fd\u6570<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">COUNT(col)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u7edf\u8ba1\u975e\u7a7a\u503c\u7684\u884c\u6570<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>COUNT(user_id) \u2192 \u7528\u6237\u603b\u6570<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">SUM(col)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u6c42\u548c<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>SUM(sales) \u2192 \u603b\u9500\u552e\u989d<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">AVG(col)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u6c42\u5e73\u5747\u503c<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>AVG(score) \u2192 \u5e73\u5747\u5206<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">MAX(col) \/ MIN(col)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u6c42\u6700\u5927\u503c\/\u6700\u5c0f\u503c<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>MAX(price) \u2192 \u6700\u9ad8\u4ef7<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u7a97\u53e3\u51fd\u6570<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">ROW_NUMBER() OVER(ORDER BY col)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u751f\u6210\u8fde\u7eed\u884c\u53f7&#xff08;\u4e0d\u91cd\u590d&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>ROW_NUMBER() OVER(ORDER BY score DESC) \u2192 \u6392\u540d1,2,3&#8230;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">RANK() OVER(ORDER BY col)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u751f\u6210\u6392\u540d&#xff08;\u6709\u95f4\u9694&#xff0c;\u59821,1,3&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>RANK() OVER(ORDER BY score DESC) \u2192 \u5e76\u5217\u7b2c1\u540e\u76f4\u63a5\u7b2c3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">DENSE_RANK() OVER(ORDER BY col)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u751f\u6210\u6392\u540d&#xff08;\u65e0\u95f4\u9694&#xff0c;\u59821,1,2&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>DENSE_RANK() OVER(ORDER BY score DESC) \u2192 \u5e76\u5217\u7b2c1\u540e\u4ecd\u7b2c2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">SUM(col) OVER(PARTITION BY col ORDER BY col)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u5206\u7ec4\u7d2f\u8ba1\u6c42\u548c<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>SUM(sales) OVER(PARTITION BY department ORDER BY month) \u2192 \u90e8\u95e8\u6708\u5ea6\u7d2f\u8ba1\u9500\u552e\u989d<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u6761\u4ef6\u51fd\u6570<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">CASE WHEN condition THEN result ELSE other END<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u591a\u6761\u4ef6\u5224\u65ad<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>CASE WHEN score &gt;&#061; 60 THEN &#039;\u53ca\u683c&#039; ELSE &#039;\u4e0d\u53ca\u683c&#039; END<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">IFNULL(expr, replace)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u7a7a\u503c\u66ff\u6362&#xff08;MySQL&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>IFNULL(phone, &#039;\u672a\u586b\u5199&#039;) \u2192 \u7a7a\u503c\u65f6\u663e\u793a\u201c\u672a\u586b\u5199\u201d<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\"><\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p><span style=\"color:#4da8ee\">COALESCE(expr1,expr2,&#8230;)<\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u8fd4\u56de\u7b2c\u4e00\u4e2a\u975e\u7a7a\u503c&#xff08;\u901a\u7528&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>COALESCE(phone, email, &#039;\u65e0\u8054\u7cfb\u65b9\u5f0f&#039;)<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>\u5fc5\u4f1a\u7684\u5e38\u7528\u51fd\u6570\u6761\u4ef6\u51fd\u65701.\u00a0IF\u00a0\u51fd\u6570IF\u00a0\u51fd\u6570\u7528\u4e8e\u6839\u636e\u6761\u4ef6\u8fd4\u56de\u4e24\u4e2a\u503c\u4e2d\u7684\u4e00\u4e2a\u3002\u5b83\u7c7b\u4f3c\u4e8e\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u00a0if-else\u00a0\u8bed\u53e5\u8bed\u6cd5&#xff1a;IF(condition, true_value, false_value)condition&#xff1a;\u6761\u4ef6true_value&#xff1a;\u5982\u679c\u6761\u4ef6\u4e3a\u00a0TRUE&#xff0c;\u5219\u8fd4\u56de\u7684\u503c\u3002false_value&#xff1a;\u5982\u679c\u6761\u4ef6\u4e3a\u00a0FALSE&#xff0c;\u5219\u8fd4\u56de\u7684\u503c\u30022.\u00a0CASE\u00a0\u8bed\u53e5CASE\u00a0\u8bed\u53e5\u7528\u4e8e\u6839\u636e\u591a\u4e2a\u6761\u4ef6\u8fd4<\/p>\n","protected":false},"author":2,"featured_media":77575,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[114,768,100],"topic":[],"class_list":["post-77592","post","type-post","status-publish","format-standard","has-post-thumbnail","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>\u96f6\u57fa\u7840SQL\u5feb\u901f\u5165\u95e8_\u725b\u5ba2\u5237\u9898\u6307\u5357:26~29 \u624b\u628a\u624b\u5e26\u5237\u5fc5\u4f1a\u7684\u5e38\u7528\u51fd\u6570,\u6761\u4ef6\u51fd\u6570,\u65e5\u671f\u51fd\u6570 - \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\/77592.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u96f6\u57fa\u7840SQL\u5feb\u901f\u5165\u95e8_\u725b\u5ba2\u5237\u9898\u6307\u5357:26~29 \u624b\u628a\u624b\u5e26\u5237\u5fc5\u4f1a\u7684\u5e38\u7528\u51fd\u6570,\u6761\u4ef6\u51fd\u6570,\u65e5\u671f\u51fd\u6570 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5fc5\u4f1a\u7684\u5e38\u7528\u51fd\u6570\u6761\u4ef6\u51fd\u65701.\u00a0IF\u00a0\u51fd\u6570IF\u00a0\u51fd\u6570\u7528\u4e8e\u6839\u636e\u6761\u4ef6\u8fd4\u56de\u4e24\u4e2a\u503c\u4e2d\u7684\u4e00\u4e2a\u3002\u5b83\u7c7b\u4f3c\u4e8e\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u00a0if-else\u00a0\u8bed\u53e5\u8bed\u6cd5&#xff1a;IF(condition, true_value, false_value)condition&#xff1a;\u6761\u4ef6true_value&#xff1a;\u5982\u679c\u6761\u4ef6\u4e3a\u00a0TRUE&#xff0c;\u5219\u8fd4\u56de\u7684\u503c\u3002false_value&#xff1a;\u5982\u679c\u6761\u4ef6\u4e3a\u00a0FALSE&#xff0c;\u5219\u8fd4\u56de\u7684\u503c\u30022.\u00a0CASE\u00a0\u8bed\u53e5CASE\u00a0\u8bed\u53e5\u7528\u4e8e\u6839\u636e\u591a\u4e2a\u6761\u4ef6\u8fd4\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/77592.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-24T15:34:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153359-699dc4e7761c1.png\" \/>\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=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/77592.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/77592.html\",\"name\":\"\u96f6\u57fa\u7840SQL\u5feb\u901f\u5165\u95e8_\u725b\u5ba2\u5237\u9898\u6307\u5357:26~29 \u624b\u628a\u624b\u5e26\u5237\u5fc5\u4f1a\u7684\u5e38\u7528\u51fd\u6570,\u6761\u4ef6\u51fd\u6570,\u65e5\u671f\u51fd\u6570 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-24T15:34:02+00:00\",\"dateModified\":\"2026-02-24T15:34:02+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/77592.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/77592.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/77592.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u96f6\u57fa\u7840SQL\u5feb\u901f\u5165\u95e8_\u725b\u5ba2\u5237\u9898\u6307\u5357:26~29 \u624b\u628a\u624b\u5e26\u5237\u5fc5\u4f1a\u7684\u5e38\u7528\u51fd\u6570,\u6761\u4ef6\u51fd\u6570,\u65e5\u671f\u51fd\u6570\"}]},{\"@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":"\u96f6\u57fa\u7840SQL\u5feb\u901f\u5165\u95e8_\u725b\u5ba2\u5237\u9898\u6307\u5357:26~29 \u624b\u628a\u624b\u5e26\u5237\u5fc5\u4f1a\u7684\u5e38\u7528\u51fd\u6570,\u6761\u4ef6\u51fd\u6570,\u65e5\u671f\u51fd\u6570 - \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\/77592.html","og_locale":"zh_CN","og_type":"article","og_title":"\u96f6\u57fa\u7840SQL\u5feb\u901f\u5165\u95e8_\u725b\u5ba2\u5237\u9898\u6307\u5357:26~29 \u624b\u628a\u624b\u5e26\u5237\u5fc5\u4f1a\u7684\u5e38\u7528\u51fd\u6570,\u6761\u4ef6\u51fd\u6570,\u65e5\u671f\u51fd\u6570 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5fc5\u4f1a\u7684\u5e38\u7528\u51fd\u6570\u6761\u4ef6\u51fd\u65701.\u00a0IF\u00a0\u51fd\u6570IF\u00a0\u51fd\u6570\u7528\u4e8e\u6839\u636e\u6761\u4ef6\u8fd4\u56de\u4e24\u4e2a\u503c\u4e2d\u7684\u4e00\u4e2a\u3002\u5b83\u7c7b\u4f3c\u4e8e\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u00a0if-else\u00a0\u8bed\u53e5\u8bed\u6cd5&#xff1a;IF(condition, true_value, false_value)condition&#xff1a;\u6761\u4ef6true_value&#xff1a;\u5982\u679c\u6761\u4ef6\u4e3a\u00a0TRUE&#xff0c;\u5219\u8fd4\u56de\u7684\u503c\u3002false_value&#xff1a;\u5982\u679c\u6761\u4ef6\u4e3a\u00a0FALSE&#xff0c;\u5219\u8fd4\u56de\u7684\u503c\u30022.\u00a0CASE\u00a0\u8bed\u53e5CASE\u00a0\u8bed\u53e5\u7528\u4e8e\u6839\u636e\u591a\u4e2a\u6761\u4ef6\u8fd4","og_url":"https:\/\/www.wsisp.com\/helps\/77592.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-24T15:34:02+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224153359-699dc4e7761c1.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/77592.html","url":"https:\/\/www.wsisp.com\/helps\/77592.html","name":"\u96f6\u57fa\u7840SQL\u5feb\u901f\u5165\u95e8_\u725b\u5ba2\u5237\u9898\u6307\u5357:26~29 \u624b\u628a\u624b\u5e26\u5237\u5fc5\u4f1a\u7684\u5e38\u7528\u51fd\u6570,\u6761\u4ef6\u51fd\u6570,\u65e5\u671f\u51fd\u6570 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-24T15:34:02+00:00","dateModified":"2026-02-24T15:34:02+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/77592.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/77592.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/77592.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u96f6\u57fa\u7840SQL\u5feb\u901f\u5165\u95e8_\u725b\u5ba2\u5237\u9898\u6307\u5357:26~29 \u624b\u628a\u624b\u5e26\u5237\u5fc5\u4f1a\u7684\u5e38\u7528\u51fd\u6570,\u6761\u4ef6\u51fd\u6570,\u65e5\u671f\u51fd\u6570"}]},{"@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\/77592","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=77592"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/77592\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/77575"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=77592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=77592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=77592"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=77592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}