{"id":1137,"date":"2015-04-21T16:13:04","date_gmt":"2015-04-21T08:13:04","guid":{"rendered":"http:\/\/www.821121.com\/?p=1137"},"modified":"2020-12-17T16:13:21","modified_gmt":"2020-12-17T08:13:21","slug":"oracle-sql%e8%af%ad%e5%8f%a5-%e4%b9%8b-case-when%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"http:\/\/www.821121.com\/?p=1137","title":{"rendered":"Oracle SQL\u8bed\u53e5 \u4e4b Case When\u51fd\u6570"},"content":{"rendered":"<h1>\u5b9a\u4e49<\/h1>\n<pre><code>\u5f53\u6211\u4eec\u9700\u8981\u4ece\u6570\u636e\u6e90\u4e0a\u76f4\u63a5\u5224\u65ad\u6570\u636e\u663e\u793a\u4ee3\u8868\u7684\u542b\u4e49\u7684\u65f6\u5019\uff0c\u5c31\u53ef\u4ee5\u5728SQL\u8bed\u53e5\u4e2d\u4f7f\u7528Case When\u8fd9\u4e2a\u51fd\u6570\u4e86\u3002\nCASE WHEN\u7c7b\u4f3c\u4e8eJAVA\u8bed\u8a00\u4e2d\u7684IF ELSE\uff0c\u5176\u5177\u6709\u4e24\u79cd\u683c\u5f0f\u3002\u7b80\u5355CASE WHEN\u51fd\u6570\u548cCASE WHEN\u6761\u4ef6\u8868\u8fbe\u5f0f\u3002\n\u7b80\u5355CASE WHEN\u51fd\u6570\u53ea\u80fd\u5e94\u5bf9\u4e00\u4e9b\u7b80\u5355\u7684\u4e1a\u52a1\u573a\u666f\uff0c\u800cCASE WHEN\u6761\u4ef6\u8868\u8fbe\u5f0f\u7684\u5199\u6cd5\u5219\u66f4\u52a0\u7075\u6d3b\u3002<\/code><\/pre>\n<h1>\u8bed\u6cd5<\/h1>\n<p>case<br \/>\nwhen \u6761\u4ef61 then action1<br \/>\nwhen \u6761\u4ef62 then action2<br \/>\nwhen \u6761\u4ef63 then action3<br \/>\nwhen \u6761\u4ef6N then actionN<br \/>\nelse action<br \/>\nend<\/p>\n<h1>\u8fd4\u56de\u503c\u7c7b\u578b<\/h1>\n<p>\u5b57\u7b26\u4e32<\/p>\n<h1>\u4e3e\u4f8b<\/h1>\n<h2>\u6b63\u5e38\u67e5\u8be2<\/h2>\n<pre><code class=\"language-sql\">select * from test_1<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2020\/12\/image-1608192428486.png\" alt=\"file\" \/><\/p>\n<h2>\u52a0\u5165CASE WHEN\u51fd\u6570\u6765\u8fd4\u56de\u9700\u8981\u7684\u503c<\/h2>\n<pre><code class=\"language-sql\">select sum(population) as \u4eba\u53e3\u603b\u6570,\n       case country\n         when &#039;\u4e2d\u56fd&#039; then\n          &#039;\u4e9a\u6d32&#039;\n         when &#039;\u5370\u5ea6&#039; then\n          &#039;\u4e9a\u6d32&#039;\n         when &#039;\u65e5\u672c&#039; then\n          &#039;\u4e9a\u6d32&#039;\n         when &#039;\u7f8e\u56fd&#039; then\n          &#039;\u5317\u7f8e\u6d32&#039;\n         when &#039;\u52a0\u62ff\u5927&#039; then\n          &#039;\u5317\u7f8e\u6d32&#039;\n         when &#039;\u58a8\u897f\u54e5&#039; then\n          &#039;\u5317\u7f8e\u6d32&#039;\n         else\n          &#039;\u5176\u5b83\u6d32&#039;\n       end as \u6d32\n  from test_1\n group by case country\n            when &#039;\u4e2d\u56fd&#039; then\n             &#039;\u4e9a\u6d32&#039;\n            when &#039;\u5370\u5ea6&#039; then\n             &#039;\u4e9a\u6d32&#039;\n            when &#039;\u65e5\u672c&#039; then\n             &#039;\u4e9a\u6d32&#039;\n            when &#039;\u7f8e\u56fd&#039; then\n             &#039;\u5317\u7f8e\u6d32&#039;\n            when &#039;\u52a0\u62ff\u5927&#039; then\n             &#039;\u5317\u7f8e\u6d32&#039;\n            when &#039;\u58a8\u897f\u54e5&#039; then\n             &#039;\u5317\u7f8e\u6d32&#039;\n            else\n             &#039;\u5176\u5b83\u6d32&#039;\n          end;<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2020\/12\/image-1608192500056.png\" alt=\"file\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9a\u4e49 \u5f53\u6211\u4eec\u9700\u8981\u4ece\u6570\u636e\u6e90\u4e0a\u76f4\u63a5\u5224\u65ad\u6570\u636e\u663e\u793a\u4ee3\u8868\u7684\u542b<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[],"class_list":["post-1137","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"http:\/\/www.821121.com\/index.php?rest_route=\/wp\/v2\/posts\/1137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.821121.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.821121.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.821121.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.821121.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1137"}],"version-history":[{"count":1,"href":"http:\/\/www.821121.com\/index.php?rest_route=\/wp\/v2\/posts\/1137\/revisions"}],"predecessor-version":[{"id":1148,"href":"http:\/\/www.821121.com\/index.php?rest_route=\/wp\/v2\/posts\/1137\/revisions\/1148"}],"wp:attachment":[{"href":"http:\/\/www.821121.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.821121.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1137"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.821121.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}