{"id":1060,"date":"2020-04-15T23:59:44","date_gmt":"2020-04-15T14:59:44","guid":{"rendered":"https:\/\/obenkyolab.com\/?p=1060"},"modified":"2020-05-19T22:49:11","modified_gmt":"2020-05-19T13:49:11","slug":"%e3%80%90postgresql%e3%80%91%e3%83%87%e3%83%bc%e3%82%bf%e3%81%ae%e7%b8%a6%e6%8c%81%e3%81%a1%e6%a8%aa%e6%8c%81%e3%81%a1%e5%a4%89%e6%8f%9b%e3%81%a7%e5%89%8d%e5%b9%b4%e6%af%94%e8%bc%83%e3%82%92%e3%81%99","status":"publish","type":"post","link":"https:\/\/obenkyolab.com\/?p=1060","title":{"rendered":"\u3010PostgreSQL\u3011\u7e26\u6301\u3061\u30c7\u30fc\u30bf\u3092\u6a2a\u6301\u3061\u5909\u63db\u3057\u524d\u5e74\u540c\u6708\u3068\u306e\u6bd4\u8f03\u3092\u3059\u308b"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/obenkyolab.com\/?p=1060\/#%E7%9B%AE%E7%9A%84\" >\u76ee\u7684<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/obenkyolab.com\/?p=1060\/#%E5%85%83%E3%83%87%E3%83%BC%E3%82%BF\" >\u5143\u30c7\u30fc\u30bf<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/obenkyolab.com\/?p=1060\/#%E6%A8%AA%E6%8C%81%E3%81%AB%E3%81%99%E3%82%8B%EF%BC%B3%EF%BC%B1%EF%BC%AC\" >\u6a2a\u6301\u306b\u3059\u308b\uff33\uff31\uff2c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/obenkyolab.com\/?p=1060\/#%E7%B5%90%E6%9E%9C\" >\u7d50\u679c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/obenkyolab.com\/?p=1060\/#%E3%81%BE%E3%81%A8%E3%82%81\" >\u307e\u3068\u3081<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%9B%AE%E7%9A%84\"><\/span>\u76ee\u7684<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u30b7\u30b9\u30c6\u30e0\u304b\u3089\u53d6\u308a\u51fa\u3057\u305f\u30c7\u30fc\u30bf\u306f\u6b63\u898f\u5316\u3055\u308c\u3066\u304a\u308a\u7e26\u6301\u3061\u306e\u30c7\u30fc\u30bf\u69cb\u9020\u304c\u591a\u3044\u3067\u3059\u304c\u3001\u53e3\u5ea7\u306e\u6b8b\u9ad8\u3084\u30ab\u30fc\u30c9\u306e\u652f\u6255\u3044\u91d1\u984d\u306a\u3069\u3001\u524d\u5e74\u306e\u5b9f\u7e3e\u3068\u6bd4\u8f03\u3059\u308b\u3088\u3046\u306a\u5834\u5408\u306b\u306f\u6a2a\u6301\u306e\u307b\u3046\u304c\u898b\u3084\u3059\u3044\u3002\u305d\u3053\u3067\u3001PostgreSQL\u3067\u7e26\u6301\u3061\u306e\u30c7\u30fc\u30bf\u3092\u6a2a\u6301\u306b\u3057\u3066\u307f\u308b\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%85%83%E3%83%87%E3%83%BC%E3%82%BF\"><\/span>\u5143\u30c7\u30fc\u30bf<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30c7\u30fc\u30bf\u3092\u4f8b\u306b\u8003\u3048\u307e\u3059\u3002\u3053\u306e\u3088\u3046\u306a\u7e26\u6301\u3061\u30c7\u30fc\u30bf\u306e\u5834\u5408\u3001\u3084\u306f\u308a\u524d\u5e74\u5ea6\u3068\u6bd4\u8f03\u3059\u308b\u306e\u304c\u5927\u5909\u3067\u3059\u3002\u7279\u306b\u30ec\u30b3\u30fc\u30c9\u304c\u5897\u3048\u308b\u306b\u3064\u308c\u3066\u3001\u6bd4\u8f03\u304c\u56f0\u96e3\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# select * from test_kingaku;\n  \u5e74  | \u6708 |  \u91d1\u984d\n------+----+--------\n 2017 |  1 | 222400\n 2017 |  2 | 237900\n 2017 |  3 | 244100\n 2017 |  4 | 208400\n 2017 |  5 | 237100\n 2017 |  6 | 208700\n 2017 |  7 | 210600\n 2017 |  8 | 291300\n 2017 |  9 | 256200\n 2017 | 10 | 232200\n 2017 | 11 | 240000\n 2017 | 12 | 204000\n 2018 |  1 | 241500\n 2018 |  2 | 226300\n 2018 |  3 | 211900\n 2018 |  4 | 241000\n 2018 |  5 | 264800\n 2018 |  6 | 207800\n 2018 |  7 | 241700\n 2018 |  8 | 278200\n 2018 |  9 | 291900\n 2018 | 10 | 241700\n 2018 | 11 | 204700\n 2018 | 12 | 206500\n 2019 |  1 | 298500\n 2019 |  2 | 254900\n 2019 |  3 | 285400\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%A8%AA%E6%8C%81%E3%81%AB%E3%81%99%E3%82%8B%EF%BC%B3%EF%BC%B1%EF%BC%AC\"><\/span>\u6a2a\u6301\u306b\u3059\u308b\uff33\uff31\uff2c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u6b21\u306e\u3088\u3046\u306aSQL\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nselect\n\t\u5e74 as \u5e74\n\t,max(\uff11\u6708) as \uff11\u6708\n\t,max(\uff12\u6708) as \uff12\u6708\n\t,max(\uff13\u6708) as \uff13\u6708\n\t,max(\uff14\u6708) as \uff14\u6708\n\t,max(\uff15\u6708) as \uff15\u6708\n\t,max(\uff16\u6708) as \uff16\u6708\n\t,max(\uff17\u6708) as \uff17\u6708\n\t,max(\uff18\u6708) as \uff18\u6708\n\t,max(\uff19\u6708) as \uff19\u6708\n\t,max(\uff11\uff10\u6708) as \uff11\uff10\u6708\n\t,max(\uff11\uff11\u6708) as \uff11\uff11\u6708\n\t,max(\uff11\uff12\u6708) as \uff11\uff12\u6708\nfrom\n\t(\n\tselect\n\t\t\u5e74\n\t\t,case \u6708\n\t\t\twhen 1 then \u91d1\u984d\n\t\t\telse null\n\t\tend as \uff11\u6708\n\t\t,case \u6708\n\t\t\twhen 2 then \u91d1\u984d\n\t\t\telse null\n\t\tend as \uff12\u6708\n\t\t,case \u6708\n\t\t\twhen 3 then \u91d1\u984d\n\t\t\telse null\n\t\tend as \uff13\u6708\n\t\t,case \u6708\n\t\t\twhen 4 then \u91d1\u984d\n\t\t\telse null\n\t\tend as \uff14\u6708\n\t\t,case \u6708\n\t\t\twhen 5 then \u91d1\u984d\n\t\t\telse null\n\t\tend as \uff15\u6708\n\t\t,case \u6708\n\t\t\twhen 6 then \u91d1\u984d\n\t\t\telse null\n\t\tend as \uff16\u6708\n\t\t,case \u6708\n\t\t\twhen 7 then \u91d1\u984d\n\t\t\telse null\n\t\tend as \uff17\u6708\n\t\t,case \u6708\n\t\t\twhen 8 then \u91d1\u984d\n\t\t\telse null\n\t\tend as \uff18\u6708\n\t\t,case \u6708\n\t\t\twhen 9 then \u91d1\u984d\n\t\t\telse null\n\t\tend as \uff19\u6708\n\t\t,case \u6708\n\t\t\twhen 10 then \u91d1\u984d\n\t\t\telse null\n\t\tend as \uff11\uff10\u6708\n\t\t,case \u6708\n\t\t\twhen 11 then \u91d1\u984d\n\t\t\telse null\n\t\tend as \uff11\uff11\u6708\n\t\t,case \u6708\n\t\t\twhen 12 then \u91d1\u984d\n\t\t\telse null\n\t\tend as \uff11\uff12\u6708\n\tfrom test_kingaku\n\t) as t0\ngroup by \u5e74\n<\/pre><\/div>\n\n\n<p>\u30dd\u30a4\u30f3\u30c8\u3057\u3066\u306f\u4ee5\u4e0b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\uff11\u6708\u304b\u3089\uff11\uff12\u6708\u307e\u3067\u306e\u30ab\u30e9\u30e0\u3092\u4f5c\u308a\u3001\u5404\u30ab\u30e9\u30e0\u3067\u306f\u8a72\u5f53\u3059\u308b\u6708\u306e\u30ec\u30b3\u30fc\u30c9\u306e\u6570\u5b57\u3060\u3051\u3092\u683c\u7d0d\u3057\u305d\u308c\u4ee5\u5916\u306f\uff2e\uff35\uff2c\uff2c\u3092\u5165\u308c\u308b\uff08\u30b5\u30d6\u30af\u30a8\u30ea\u90e8\uff09<\/li><li>\u5e74\u3067group by\u3057\u3001\u5404\u6708\u306emax\u306e\u5024\u3092\u53d6\u308a\u51fa\u3059\u3002\u3053\u306e\u64cd\u4f5c\u306b\u3088\u308a\uff2e\uff35\uff2c\uff2c\u306e\u30ec\u30b3\u30fc\u30c9\u304c\u9664\u5916\u3055\u308c\u308b\u3002<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%B5%90%E6%9E%9C\"><\/span>\u7d50\u679c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u3059\u3002\u3053\u308c\u3060\u3068\u524d\u5e74\u306e\u540c\u6708\u3068\u306e\u6bd4\u8f03\u304c\u4e00\u76ee\u77ad\u7136\u3067\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n  \u5e74  |  \uff11\u6708  |  \uff12\u6708  |  \uff13\u6708  |  \uff14\u6708  |  \uff15\u6708  |  \uff16\u6708  |  \uff17\u6708  |  \uff18\u6708  |  \uff19\u6708  | \uff11\uff10\u6708 | \uff11\uff11\u6708 | \uff11\uff12\u6708\n------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------\n 2017 | 222400 | 237900 | 244100 | 208400 | 237100 | 208700 | 210600 | 291300 | 256200 | 232200 | 240000 | 204000\n 2018 | 241500 | 226300 | 211900 | 241000 | 264800 | 207800 | 241700 | 278200 | 291900 | 241700 | 204700 | 206500\n 2019 | 298500 | 254900 | 285400 | 214500 | 269700 | 247200 | 282800 | 270000 | 272400 | 226600 | 214600 | 236100\n(3 \u884c)\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E3%81%BE%E3%81%A8%E3%82%81\"><\/span>\u307e\u3068\u3081<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u30b7\u30b9\u30c6\u30e0\u304b\u3089\u53d6\u308a\u51fa\u3057\u305f\u7e26\u6301\u3061\u30c7\u30fc\u30bf\u3092\u524d\u5e74\u3084\u524d\u306e\u6708\u3068\u6bd4\u8f03\u5206\u6790\u3059\u308b\u969b\u306f\uff33\uff31\uff2c\u3067\u7e26\u6301\u3061\u306b\u3059\u308b\u3068\u308f\u304b\u308a\u3084\u3059\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u7684 \u30b7\u30b9\u30c6\u30e0\u304b\u3089\u53d6\u308a\u51fa\u3057\u305f\u30c7\u30fc\u30bf\u306f\u6b63\u898f\u5316\u3055\u308c\u3066\u304a\u308a\u7e26\u6301\u3061\u306e\u30c7\u30fc\u30bf\u69cb&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1042,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"https:\/\/obenkyolab.com\/?p=1060","footnotes":""},"categories":[12],"tags":[34],"class_list":["post-1060","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-postgresql","tag-sql","ja"],"_links":{"self":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/1060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1060"}],"version-history":[{"count":5,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/1060\/revisions"}],"predecessor-version":[{"id":1065,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/1060\/revisions\/1065"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/media\/1042"}],"wp:attachment":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}