{"id":623,"date":"2025-08-08T15:47:24","date_gmt":"2025-08-08T06:47:24","guid":{"rendered":"https:\/\/www.flumen-jp.com\/wordpress\/?p=623"},"modified":"2025-08-08T22:44:20","modified_gmt":"2025-08-08T13:44:20","slug":"text-to-sql","status":"publish","type":"post","link":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/2025\/08\/08\/text-to-sql\/","title":{"rendered":"Text-to-SQL"},"content":{"rendered":"\n<p>\u3000\u6628\u65e5\u3001\u3068\u3042\u308b\u30ea\u30e2\u30fc\u30c8\u4f1a\u8b70\u3067<a href=\"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/2025\/07\/24\/lean_sql\/\">\u524d\u56de\u306e\u8a18\u4e8b<\/a>\u306b\u985e\u3059\u308b\u304a\u8a71\u3092\u3057\u305f\u3068\u3053\u308d\u3001\u51fa\u5e2d\u8005\u304b\u3089\u300c\u3053\u306e SQL \u306f AI \u3067\u751f\u6210\u3067\u304d\u308b\u304b\u306a\u300d\u3068\u306e\u767a\u8a00\u304c\u3042\u308a\u307e\u3057\u305f\u3002<br>\u3000\u8abf\u3079\u305f\u3068\u3053\u308d\u300cText-to-SQL\u300d\u3068\u8a00\u3063\u3066\u3001\u3053\u3046\u3044\u3063\u305f\u4e8b\u306f\u6628\u4eca\u3054\u304f\u666e\u901a\u306b\u884c\u308f\u308c\u3066\u3044\u308b\u6a21\u69d8\u3002\u3068\u3044\u3046\u8a33\u3067\u3001\u4f55\u3068\u306a\u304f\u3053\u308c\u307e\u3067\u907f\u3051\u3066\u304d\u305f\u751f\u6210 AI \u306b\u30c8\u30e9\u30a4\u3057\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u305f\u3002<br>\u3000ChatGPT \u306f\u65b0\u898f\u30e6\u30fc\u30b6\u30fc\u767b\u9332\u304c\u5fc5\u8981\u306a\u306e\u3067\u30d1\u30b9\u3057\u3066\u3001\u4eca\u56de\u304a\u4e16\u8a71\u306b\u306a\u3063\u305f\u306e\u306f <a href=\"https:\/\/gemini.google.com\/app?hl=ja\">Gemini<\/a>\uff08\u30c1\u30fc\u30e0\u307f\u3089\u3044\u306e\u5b89\u91ce\u6c0f\u304c\u300c\u30b8\u30a7\u30df\u30ca\u30a4\u300d\u3068\u767a\u97f3\u3057\u3066\u3044\u305f\uff09\u3002\u9078\u629e\u3057\u305f\u30e2\u30c7\u30eb\u306f\u300c\u63a8\u8ad6\u30fb\u6570\u5b66\u30fb\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u300d\u5411\u3051\u306e 2.5Pro\u3002<\/p>\n\n\n\n<p>\u3000\u524d\u56de\u306e\u8ab2\u984c\u306b\u5247\u3057\u3066\u6295\u3052\u305f\u8cea\u554f\u306f\u4ee5\u4e0b\u3002<\/p>\n\n\n\n<p><em>\u65e5\u5225\u306e\u96e8\u91cf\u30c7\u30fc\u30bf rainfall.csv \u304c\u3042\u308a\u307e\u3059\u30021 \u30ab\u30e9\u30e0\u76ee\u306e date \u306f\u65e5\u4ed8\u6587\u5b57\u5217\u30012 \u30ab\u30e9\u30e0\u76ee\u306e value \u306f\u5b9f\u6570\u578b\u306e 1 \u65e5\u96e8\u91cf\u3067\u3059\u3002\u30ec\u30b3\u30fc\u30c9\u306f date \u3067\u30bd\u30fc\u30c8\u6e08\u307f\u3067\u3059\u3002<br>SQLite \u3067 rainfall.csv \u3092 rainfall \u30c6\u30fc\u30d6\u30eb\u306b\u5c55\u958b\u3057\u305f\u3046\u3048\u3067 1 \u65e5\u30012 \u65e5\u30013 \u65e5\u306e\u9023\u7d9a\u96e8\u91cf\u306e\u6700\u5927\u5024\u3092\u5e74\u5225\u306b\u62bd\u51fa\u3059\u308b SQL \u3092\u751f\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/em><\/p>\n\n\n\n<p>\u3000\u56de\u7b54\u3067\u5f97\u3089\u308c\u305f SQL \u306f\u4ee5\u4e0b\u306e\u4e8c\u3064\uff08\u5b9f\u969b\u306f\u89e3\u8aac\u4ed8\u304d\u306a\u306e\u3067\u8208\u5473\u304c\u3042\u308b\u65b9\u306f\u540c\u3058\u8cea\u554f\u3092\u6295\u3052\u3066\u78ba\u8a8d\u3055\u308c\u305f\u3044\uff09\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>-- rainfall \u30c6\u30fc\u30d6\u30eb\u306e\u4f5c\u6210\nCREATE TABLE rainfall (\n  date TEXT PRIMARY KEY,\n  value REAL\n);\n\n-- (SQLite\u306e\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u30c4\u30fc\u30eb\u3067\u4ee5\u4e0b\u3092\u5b9f\u884c)\n-- .mode csv\n-- .import rainfall.csv rainfall<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>WITH ConsecutiveRainfall AS (\n  SELECT\n    strftime(&#39;%Y&#39;, date) AS year,\n    value AS one_day_rainfall,\n    -- 2\u65e5\u9023\u7d9a\u96e8\u91cf (\u5f53\u65e5 + \u524d\u65e5)\n    value + LAG(value, 1, 0) OVER (ORDER BY date) AS two_day_rainfall,\n    -- 3\u65e5\u9023\u7d9a\u96e8\u91cf (\u5f53\u65e5 + \u524d\u65e5 + \u524d\u3005\u65e5)\n    value + LAG(value, 1, 0) OVER (ORDER BY date)\n          + LAG(value, 2, 0) OVER (ORDER BY date) AS three_day_rainfall\n  FROM\n    rainfall\n)\nSELECT\n  year,\n  MAX(one_day_rainfall) AS max_1_day_rainfall,\n  MAX(two_day_rainfall) AS max_2_day_rainfall,\n  MAX(three_day_rainfall) AS max_3_day_rainfall\nFROM\n  ConsecutiveRainfall\nGROUP BY\n  year\nORDER BY\n  year;<\/code><\/pre><\/div>\n\n\n\n<p>\u3000<a href=\"https:\/\/techplay.jp\/column\/1702\" target=\"_blank\" rel=\"noreferrer noopener\">WITH \u53e5<\/a>\u3084 <a href=\"https:\/\/products.sint.co.jp\/siob\/blog\/sql-bootcamp-17\" target=\"_blank\" rel=\"noreferrer noopener\">LAG \u95a2\u6570<\/a>\u306e\u5229\u7528\u306a\u3069\u524d\u56de\u306e SQL \u3068\u7570\u306a\u308b\u3082\u306e\u306e\uff08\u3053\u3061\u3089\u306e\u65b9\u304c\u30d9\u30bf\u30fc\uff1f\uff09\u5185\u5bb9\u306f\u540c\u4e00\u3002\u65b0\u305f\u306a\u30c6\u30fc\u30d6\u30eb\u30fb\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u547d\u540d\u3082\u9069\u5207\u3002\u6b63\u5e38\u52d5\u4f5c\u3082\u78ba\u8a8d\u3055\u308c\u305f\u3002<\/p>\n\n\n\n<p>\u3000\u4ee5\u4e0a\u3001<strong>Text-to-SQL \u306f\u975e\u5e38\u306b\u5f79\u7acb\u3064<\/strong>\u3002<br>\u3000\u3057\u304b\u3057\u306a\u304c\u3089\u3001\u7d50\u5c40\u3001AI \u306e\u56de\u7b54\u306e\u5f53\u5426\u3092\u5224\u65ad\u3059\u308b\u306e\u306f\u4eba\u9593\u306a\u306e\u3067\u3001AI \u3068\u306e\u5354\u696d\u3068\u3044\u3046\u306e\u304c\u6b63\u3057\u3044\u30b9\u30bf\u30f3\u30b9\u306a\u306e\u3060\u3068\u601d\u3046\u3002\u3064\u307e\u308a\u5f53\u65b9\u3082\u5b66\u7fd2\u306e\u5f37\u5316\u304c\u5fc5\u8981\u3060\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u6628\u65e5\u3001\u3068\u3042\u308b\u30ea\u30e2\u30fc\u30c8\u4f1a\u8b70\u3067\u524d\u56de\u306e\u8a18\u4e8b\u306b\u985e\u3059\u308b\u304a\u8a71\u3092\u3057\u305f\u3068\u3053\u308d\u3001\u51fa\u5e2d\u8005\u304b\u3089\u300c\u3053\u306e SQL \u306f AI \u3067\u751f\u6210\u3067\u304d\u308b\u304b\u306a\u300d\u3068\u306e\u767a\u8a00\u304c\u3042\u308a\u307e\u3057\u305f\u3002\u3000\u8abf\u3079\u305f\u3068\u3053\u308d\u300cText-to-SQL\u300d\u3068\u8a00\u3063\u3066\u3001\u3053\u3046\u3044\u3063\u305f\u4e8b\u306f\u6628\u4eca\u3054\u304f\u666e\u901a\u306b\u884c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[49,50,24,51],"class_list":["post-623","post","type-post","status-publish","format-standard","hentry","category-it","tag-ai","tag-gemini","tag-sql","tag-text-to-sql"],"_links":{"self":[{"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=623"}],"version-history":[{"count":23,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/623\/revisions"}],"predecessor-version":[{"id":649,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/623\/revisions\/649"}],"wp:attachment":[{"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}