{"id":172443,"date":"2020-10-26T01:42:05","date_gmt":"2020-10-25T17:42:05","guid":{"rendered":"http:\/\/4563.org\/?p=172443"},"modified":"2020-10-26T01:42:05","modified_gmt":"2020-10-25T17:42:05","slug":"%e8%af%b7%e6%95%99%e4%b8%80%e6%9d%a1-sql-%e8%af%ad%e5%8f%a5%ef%bc%8c%e6%a0%b9%e6%8d%ae%e6%9d%a1%e4%bb%b6-select-%e6%9c%89%e8%bf%98%e6%98%af%e6%b2%a1%e6%9c%89%ef%bc%8c%e5%81%9a%e6%89%a7%e8%a1%8c","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=172443","title":{"rendered":"\u8bf7\u6559\u4e00\u6761 SQL \u8bed\u53e5\uff0c\u6839\u636e\u6761\u4ef6 SELECT \u6709\u8fd8\u662f\u6ca1\u6709\uff0c\u505a\u6267\u884c\u5176\u5b83\u7684\u8bed\u53e5\u3002\u3002\u3002"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u6559\u4e00\u6761 SQL \u8bed\u53e5\uff0c\u6839\u636e\u6761\u4ef6 SELECT \u6709\u8fd8\u662f\u6ca1\u6709\uff0c\u505a\u6267\u884c\u5176\u5b83\u7684\u8bed\u53e5\u3002\u3002\u3002               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : qazwsxkevin <\/span>  <span><i><\/i> 9<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>SELECT CASE         WHEN (SELECT count(1) FROM TestTable WHERE `FeedID`='666')&gt;0        THEN             'true'         WHEN  (SELECT count(1) FROM TestTable WHERE `FeedID`='666')=0        THEN            INSERT INTO TestTable (`FeedName`,`FeedID`) VALUES ('kkk','666')        END 'Result'; <\/code><\/pre>\n<p>\u6211\u662f\u60f3\u5982\u679c\u6ca1\u6709<code>FeedID<\/code>=&#8217;666&#8217;\uff0c\u5c31\u63d2\u5165\u4e00\u6761\uff0c<\/p>\n<p>\u4f46\u5982\u679c\u6709<br \/> \u6211\u662f\u60f3\u5728&#8217;true&#8217;\u54ea\u91cc\u518d\u6dfb\u52a0\u4e00\u4e9b\u52a8\u4f5c\u7684\uff0c<br \/> \u53ea\u662f\u73b0\u5728\u60f3\u6d4b\u8bd5&#8217;false&#8217;\u7684\u529f\u80fd\uff0c\u90fd\u6ca1\u80fd\u901a\u8fc7\u4e86\uff0c\u8bed\u6cd5\u6709\u9519\uff1f \u8fd8\u662f CASE WHEN \u4e0d\u5141\u8bb8\u8fd9\u6837\u64cd\u4f5c\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>8<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3788247\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xumng123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             laravel orm withcount()                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3788248\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xlui <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u8c08\u6709\u6ca1\u6709\u4f60\u5e0c\u671b\u7684\u89e3\u51b3\u65b9\u6848\u3002<br \/>\u5efa\u8bae\u653e\u5230\u4e8b\u52a1\u91cc\u505a\uff0cSQL \u4e0d\u8981\u9644\u5e26\u590d\u6742\u903b\u8f91\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3788249\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : myevery <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u79cd\u5728\u7a0b\u5e8f\u91cc\u5224\u65ad\u6267\u884c\u4e0d\u9999\u4e48                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3788250\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lihongming <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @myevery \u6211\u731c\u8fd9\u53ef\u80fd\u662f\u9762\u8bd5\u9898                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3788251\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : qazwsxkevin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @xumng123 \u7528\u7684\u73af\u5883\u662f Python\uff0c\u6ca1\u6709 PHP\uff0c\u641c\u8fd9\u4e2a\u4e4b\u524d\u8fd8\u4e0d\u77e5\u9053\u662f\u4ec0\u4e48\uff0c\u54c8\u54c8<\/p>\n<p>@xlui\uff0c\u77e5\u9053\u7684\uff0c\u81f3\u4e8e\u4e3a\u4ec0\u4e48\uff0c\u540e\u9762\u8bf4<\/p>\n<p>@myevery\uff0c\u6709\u5c34\u5c2c\u7684\u56f0\u96be\u3002\u3002<\/p>\n<p>@lihongming \u54c7\uff0c\u8fd9\u4e2a\u95ee\u9898\u80fd\u505a\u9762\u8bd5\u9898\uff0c\u90a3\u4e48\u53ef\u80fd\u662f\u6709\u96be\u5ea6\u4e86\u3002\u3002\u3002<\/p>\n<p>\u4e8b\u60c5\u662f\u81ea\u5df1\u6298\u817e\u7684\uff0c\u4e0d\u662f\u516c\u53f8\u548c\u5546\u4e1a\u73af\u5883\uff0c\u5141\u8bb8\u4e0d\u9075\u5b88\u4e00\u4e9b\u4e8b\u60c5\u4e71\u6765\uff0c\u662f\u8fd9\u6837\u7684\uff1a\u8981\u505a\u8fd9\u4e2a\u64cd\u4f5c\uff0c\u662f\u5728\u7a0b\u5e8f\u5757\u91cc\u7684\u5c0f\u8282\u70b9\uff0c\u5982\u679c\u6309\u6211\u4f4e\u6c34\u5e73\u7684 Python \u7684\u505a\u6cd5\uff0c\u5b8c\u6210\u6574\u4e2a\u6700\u540e\u9700\u6c42\uff0c\u5148 SELECT\uff0c\u4ea7\u751f 10 \u6765\u4e2a\u672c\u5730\u53d8\u91cf\uff0c\u7136\u540e\u672c\u5730\u7b97\u6cd5\u5bf9\u6bd4\uff0c\u518d\u505a\u51b3\u5b9a\uff0c\u540c\u65f6\u63e1\u624b\u4f1a\u4ea7\u751f 10 \u6765\u4e2a\u77ed\u94fe\u63a5\uff0c\u53cd\u6b63\u670d\u52a1\u5668\u4e5f\u4e0d\u5fd9\uff0c\u5f04\u4e2a MySQL \u8bed\u53e5\u6254\u8fc7\u53bb\uff0c\u80fd\u7701\u5f88\u591a\u4e8b\uff0c\u540c\u65f6\u81ea\u5df1\u53ef\u4ee5\u5b66\u4e60\u4e00\u4e0b SQL \u7684\u7384\u5999\u3002\u3002\u3002 \uff0c\u5728 SQL \u8bed\u53e5\u91cc\u80fd IF ELSE\uff0c\u8fd8\u771f\u662f\u7701\u5fc3\u7684\uff0cSQL \u7684\u64cd\u4f5c\u540e\u9762\u6539\u52a8\u4e5f\u4e0d\u4f1a\u5f88\u5927\u3002<br \/>\u5982\u679c\u6309\u4e0a\u9762\u7684\u5927\u54e5\u63d0\u5230\u53ef\u4ee5\u505a\u9762\u8bd5\u9898\uff0c\u90a3\u4e48\u770b\u6765\u8fd8\u662f\u5f88\u96be\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3788252\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nuistzhou <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5367\u69fd\u8fd8\u80fd\u8fd9\u4e48\u64cd\u4f5c\u5417\uff1f select \u5d4c\u5957 insert \uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3788253\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : vone <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/www.runoob.com\/sql\/sql-insert-into-select.html                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3788254\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhangysh1995 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6309\u7167\u8bed\u6cd5\uff0cTHEN \u53ea\u53ef\u4ee5\u586b\u4e00\u4e2a\u4e00\u884c\u4e00\u5217\u7684 relation \uff08\u4e00\u4e2a\u503c\uff09\uff0cscalar query \u6ee1\u8db3\u8fd9\u4e2a\u6761\u4ef6\uff0c\u4f46\u662f false \u5206\u652f insert \u4e0d\u6ee1\u8db3\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u6559\u4e00\u6761 SQL \u8bed\u53e5\uff0c\u6839\u636e\u6761\u4ef6 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/172443"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=172443"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/172443\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=172443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=172443"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=172443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}