{"id":7038,"date":"2024-11-14T11:41:33","date_gmt":"2024-11-14T03:41:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7038\/"},"modified":"2024-11-14T11:41:33","modified_gmt":"2024-11-14T03:41:33","slug":"mysql-%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b-num-%e8%be%93%e5%87%ba%e5%a7%8b%e7%bb%88%e4%b8%ba-0%ef%bc%9a%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3-tempsno-%e5%8f%98%e9%87%8f%e6%9c%aa%e6%8c%87%e5%ae%9a","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7038\/","title":{"rendered":"MySQL \u5b58\u50a8\u8fc7\u7a0b Num \u8f93\u51fa\u59cb\u7ec8\u4e3a 0\uff1a\u5982\u4f55\u89e3\u51b3 TempSno \u53d8\u91cf\u672a\u6307\u5b9a\u9ed8\u8ba4\u503c\u7684\u95ee\u9898\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173034293760823.jpg\" class=\"aligncenter\" title=\"MySQL \u5b58\u50a8\u8fc7\u7a0b Num \u8f93\u51fa\u59cb\u7ec8\u4e3a 0\uff1a\u5982\u4f55\u89e3\u51b3 TempSno \u53d8\u91cf\u672a\u6307\u5b9a\u9ed8\u8ba4\u503c\u7684\u95ee\u9898\uff1f\u63d2\u56fe\" alt=\"MySQL \u5b58\u50a8\u8fc7\u7a0b Num \u8f93\u51fa\u59cb\u7ec8\u4e3a 0\uff1a\u5982\u4f55\u89e3\u51b3 TempSno \u53d8\u91cf\u672a\u6307\u5b9a\u9ed8\u8ba4\u503c\u7684\u95ee\u9898\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u89e3\u51b3\u5b58\u50a8\u8fc7\u7a0b num \u8f93\u51fa\u59cb\u7ec8\u4e3a 0 \u7684\u95ee\u9898<\/strong><\/p>\n<p>\u5728  \u4e2d\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\u65f6\uff0c\u7528\u6237\u7ecf\u5e38\u4f1a\u9047\u5230 num \u59cb\u7ec8\u8f93\u51fa\u4e3a 0 \u7684\u95ee\u9898\u3002\u8fd9\u4e2a\u95ee\u9898\u901a\u5e38\u662f\u56e0\u4e3a\u4ee5\u4e0b\u539f\u56e0\uff1a<\/p>\n<p><strong>\u95ee\u9898\u539f\u56e0\uff1a<\/strong><\/p>\n<p>\u5b58\u50a8\u8fc7\u7a0b\u4e2d\u672a\u4e3a <strong>tempsno<\/strong> \u53d8\u91cf\u6307\u5b9a\u9ed8\u8ba4\u503c\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u7528\u6237\u9700\u8981\u5728\u5b58\u50a8\u8fc7\u7a0b\u4e2d\u4e3a <strong>tempsno<\/strong> \u53d8\u91cf\u6307\u5b9a\u9ed8\u8ba4\u503c\u3002\u53ef\u4ee5\u901a\u8fc7\u5728\u53d8\u91cf\u58f0\u660e\u4e2d\u6dfb\u52a0\u4e00\u4e2a <strong>default<\/strong> \u5b50\u53e5\u6765\u5b9e\u73b0\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>declare tempsno varchar(30) default '';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6307\u5b9a\u9ed8\u8ba4\u503c\u540e\uff0c\u5982\u679c <strong>tsno<\/strong> \u7684\u503c\u4e3a\u7a7a\u6216\u672a\u5b9a\u4e49\uff0c<strong>tempsno<\/strong> \u5c06\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u503c\uff08\u5728\u672c\u4f8b\u4e2d\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff09\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u786e\u4fdd\u5728\u6bd4\u8f83 <strong>tsno<\/strong> \u548c <strong>tempsno<\/strong> \u4e4b\u524d\uff0c<strong>tempsno<\/strong> \u59cb\u7ec8\u5177\u6709\u975e <strong>null<\/strong> \u503c\u3002<\/p>\n<p><strong>\u4fee\u6539\u540e\u7684\u5b58\u50a8\u8fc7\u7a0b\uff1a<\/strong><\/p>\n<pre>begin\n    declare tSno varchar(30);\n    declare tScore numeric(10,2);\n    declare TempSno varchar(30) default '';    \n    declare done int default 0;    \n    declare Num int default 0;\n    declare getStudent cursor for select Sno, Score from SC order by Sno;\n    declare continue handler for SQLSTATE '02000' set done = 1;\n    open getStudent;    \n    repeat\n        fetch getStudent into tSno,tScore;\n        if(tScore&lt;60) then\n            if(tSno!=TempSno) then\n                set Num = Num + 1;\n                set TempSno = tSno;\n            end if;\n        end if;\n    until done end repeat;\n    select Num;\n    close getStudent;\nend \/\/<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u5b58\u50a8\u8fc7\u7a0b Num \u8f93\u51fa\u59cb\u7ec8\u4e3a 0\uff1a\u5982\u4f55\u89e3\u51b3 TempSno \u53d8\u91cf\u672a\u6307\u5b9a\u9ed8\u8ba4\u503c\u7684\u95ee\u9898\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u89e3\u51b3\u5b58\u50a8\u8fc7\u7a0b num \u8f93\u51fa\u59cb\u7ec8\u4e3a 0 \u7684\u95ee\u9898 \u5728 \u4e2d\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\u65f6\uff0c\u7528\u6237\u7ecf\u5e38\u4f1a\u9047\u5230 num \u59cb\u7ec8\u8f93\u51fa\u4e3a 0 \u7684\u95ee\u9898\u3002\u8fd9\u4e2a\u95ee\u9898\u901a\u5e38\u662f\u56e0\u4e3a\u4ee5\u4e0b\u539f\u56e0\uff1a \u95ee\u9898\u539f\u56e0\uff1a \u5b58\u50a8\u8fc7\u7a0b\u4e2d\u672a\u4e3a tempsno \u53d8\u91cf\u6307\u5b9a\u9ed8\u8ba4\u503c\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u7528\u6237\u9700\u8981\u5728\u5b58\u50a8\u8fc7\u7a0b\u4e2d\u4e3a tempsno \u53d8\u91cf\u6307\u5b9a\u9ed8\u8ba4\u503c\u3002\u53ef\u4ee5\u901a\u8fc7\u5728\u53d8\u91cf\u58f0\u660e\u4e2d\u6dfb\u52a0\u4e00\u4e2a default \u5b50\u53e5\u6765\u5b9e\u73b0\uff0c\u5982\u4e0b\u6240\u793a\uff1a declare tempsno varchar(30) default &#8221;; \u767b\u5f55\u540e\u590d\u5236 \u6307\u5b9a\u9ed8\u8ba4\u503c\u540e\uff0c\u5982\u679c tsno \u7684\u503c\u4e3a\u7a7a\u6216\u672a\u5b9a\u4e49\uff0ctempsno \u5c06\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u503c\uff08\u5728\u672c\u4f8b\u4e2d\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff09\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u786e\u4fdd\u5728\u6bd4\u8f83 tsno \u548c tempsno \u4e4b\u524d\uff0ctempsno \u59cb\u7ec8\u5177\u6709\u975e null \u503c\u3002 \u4fee\u6539\u540e\u7684\u5b58\u50a8\u8fc7\u7a0b\uff1a begin declare tSno varchar(30); declare tScore numeric(10,2); declare TempSno varchar(30) default &#8221;; declare done int default [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7038","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7038","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=7038"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7038\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7038"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7038"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7038"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}