{"id":1368,"date":"2021-10-17T18:22:52","date_gmt":"2021-10-17T09:22:52","guid":{"rendered":"https:\/\/sunafukin.jp\/?p=1368"},"modified":"2024-10-19T12:39:53","modified_gmt":"2024-10-19T03:39:53","slug":"sql%e3%81%ae%e3%83%81%e3%83%bc%e3%83%88%e3%82%b7%e3%83%bc%e3%83%88","status":"publish","type":"post","link":"https:\/\/sunafukin.jp\/?p=1368","title":{"rendered":"SQL\u306e\u30c1\u30fc\u30c8\u30b7\u30fc\u30c8"},"content":{"rendered":"<h2>SQL\u3068\u306f<\/h2>\n<p>SQL\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u7ba1\u7406\u30b7\u30b9\u30c6\u30e0(RDBMS)\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u5b9a\u7fa9\u3084\u64cd\u4f5c\u3092\u884c\u3046\u305f\u3081\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a00\u8a9e\u3067\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3068\u4f75\u7528\u3057\u3066\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u305f\u3081\u306b\u306f\u5229\u7528\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>SQL\u306e\u6a19\u6e96\u898f\u683c\u306f\u3001ANSI\uff08\u7c73\u56fd\u898f\u683c\u5354\u4f1a\uff09\u3084ISO\uff08\u56fd\u969b\u6a19\u6e96\u5316\u6a5f\u69cb\uff09\u3068\u3044\u3063\u305f\u6a19\u6e96\u5316\u56e3\u4f53\u306b\u3088\u3063\u3066\u6a19\u6e96\u5316\u3055\u308c\u3066\u304a\u308a\u3001\u4e00\u5ea6\u5b66\u7fd2\u3059\u308c\u3070\u3042\u3089\u3086\u308b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3067\u307b\u307c\u540c\u3058\u3088\u3046\u306a\u64cd\u4f5c\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>SQL\u306e4\u5927\u30c7\u30fc\u30bf\u64cd\u4f5c\u8a00\u8a9e(SELECT,UPDATE,DELETE,INSERT)<\/h2>\n<p>SQL\u306e\u64cd\u4f5c\u8a00\u8a9e\u306f\u3001\u4e3b\u306b4\u3064\u306e\u64cd\u4f5c\u8a00\u8a9e\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<ul>\n<li>SELECT<\/li>\n<li>UPDATE<\/li>\n<li>DELETE<\/li>\n<li>INSERT<\/li>\n<\/ul>\n<h3>SELECT<\/h3>\n<p>SELECT\u306f\u3001\u30c7\u30fc\u30bf\u306e\u691c\u7d22\u3067\u5229\u7528\u3057\u307e\u3059\u3002<br \/>\nSQL\u306e\u547d\u4ee4\u3067\u3001\u4e00\u756a\u3088\u304f\u5229\u7528\u3055\u308c\u308b\u6587\u3067\u3059\u3002<\/p>\n<pre class=\"show-lang:2 lang:mysql decode:true \" title=\"SELECT\u6587\u306e\u57fa\u672c\u7684\u306a\u66f8\u304d\u65b9\">\/* \u57fa\u672c\u7684\u306a\u66f8\u304d\u65b9 *\/\r\nSELECT *\r\nFROM \u30c6\u30fc\u30d6\u30eb\u540d\r\n    (WHERE \u6761\u4ef6\u6587) \r\n    (ORDER BY\u306a\u3069\u306e\u4fee\u98fe)\r\n\r\n\/* \u4f8b *\/\r\nSELECT *\r\nFROM \u90fd\u9053\u5e9c\u770c;\r\n\r\n\r\n\/* \u5217\u3092\u7d5e\u308a\u305f\u3044\u5834\u5408\u306e\u66f8\u304d\u65b9 *\/\r\nSELECT \u5217\u540d1,\u5217\u540d2,\uff65\uff65\uff65\r\nFROM \u30c6\u30fc\u30d6\u30eb\u540d\r\n    (WHERE \u6761\u4ef6\u6587) \r\n    (ORDER BY\u306a\u3069\u306e\u4fee\u98fe)\r\n\r\n\/* \u4f8b *\/\r\nSELECT \u90fd\u9053\u5e9c\u770c\u30b3\u30fc\u30c9,\u90fd\u9053\u5e9c\u770c\u540d\r\nFROM \u90fd\u9053\u5e9c\u770c;\r\n\r\n\r\n\/* \u5217\u540d\u3092\u5909\u66f4\u3057\u305f\u3044\u5834\u5408\u306e\u66f8\u304d\u65b9 *\/\r\nSELECT \u5217\u540d1 AS \u5217\u540d1\u306e\u5225\u540d,\u5217\u540d2 AS \u5217\u540d2\u306e\u5225\u540d,\uff65\uff65\uff65\r\nFROM \u30c6\u30fc\u30d6\u30eb\u540d\r\n    (WHERE \u6761\u4ef6\u6587) \r\n    (ORDER BY\u306a\u3069\u306e\u4fee\u98fe)\r\n\r\n\/* \u4f8b *\/\r\nSELECT \u90fd\u9053\u5e9c\u770c\u30b3\u30fc\u30c9 AS \u30b3\u30fc\u30c9,\u90fd\u9053\u5e9c\u770c\u540d AS \u540d\r\nFROM \u90fd\u9053\u5e9c\u770c;\r\n\r\n\r\n\/* \u6761\u4ef6\u3092\u7d5e\u308a\u305f\u3044\u5834\u5408\u306e\u66f8\u304d\u65b9 *\/\r\nSELECT \u5217\u540d1,\u5217\u540d2,\uff65\uff65\uff65\r\nFROM \u30c6\u30fc\u30d6\u30eb\u540d\r\nWHERE \u6761\u4ef6\u6587\r\n (ORDER BY\u306a\u3069\u306e\u4fee\u98fe)\r\n\r\n \/* \u4f8b *\/\r\nSELECT \u90fd\u9053\u5e9c\u770c\u30b3\u30fc\u30c9,\u90fd\u9053\u5e9c\u770c\u540d\r\nFROM \u90fd\u9053\u5e9c\u770c\r\nWHERE \u90fd\u9053\u5e9c\u770c\u540d = '\u6771\u4eac\u90fd';<\/pre>\n<h4>SELECT\u306e\u5b9f\u884c\u9806\u5e8f<\/h4>\n<p class=\"\">\u2460FROM<\/p>\n<p class=\"\">\u2461JOIN<\/p>\n<p class=\"\">\u2462WHERE<\/p>\n<p class=\"\">\u2463GROUP BY<\/p>\n<p class=\"\">\u2464HAVING<\/p>\n<p class=\"\">\u2465SELECT<\/p>\n<p class=\"\">\u2466ORDER BY<\/p>\n<p class=\"\">\u2467LIMIT<\/p>\n<p>SUM\u95a2\u6570\u306a\u3069\u96c6\u7d04\u95a2\u6570\u304c\u5229\u7528\u3067\u304d\u308b\u306e\u306f\u3001\u2464\u4ee5\u964d\u3002<\/p>\n<p>AS\u306b\u3088\u308b\u5225\u540d\u304c\u5229\u7528\u3067\u304d\u308b\u306e\u306f\u3001\u2465\u4ee5\u964d\u3002<\/p>\n<h3>UPDATE<\/h3>\n<p>UPDATE\u306f\u3001\u30c7\u30fc\u30bf\u306e\u66f4\u65b0\u3067\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>WHERE\u6761\u4ef6\u3092\u3064\u3051\u306a\u3044\u3068\u3001\u30c7\u30fc\u30bf\u304c\u5168\u4ef6\u66f4\u65b0\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u6c17\u3092\u3064\u3051\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"show-lang:2 lang:mysql decode:true\">\/* \u57fa\u672c\u7684\u306a\u66f8\u304d\u65b9 *\/\r\nUPDATE \u30c6\u30fc\u30d6\u30eb\u540d\r\nSET \u5217\u540d1=\u50241,\u5217\u540d2=\u50242,\u2026\r\n    (WHERE \u6761\u4ef6\u6587)\r\n\r\n\/* \u4f8b \u6c96\u7e04\u770c\u306e\u4eba\u53e3\u3092\u66f4\u65b0\u3059\u308b *\/\r\nUPDATE \u90fd\u9053\u5e9c\u770c\r\nSET \u90fd\u9053\u5e9c\u770c\u540d='\u6c96\u7e04\u770c'\r\nWHERE \u90fd\u9053\u5e9c\u770c\u30b3\u30fc\u30c9=47;<\/pre>\n<h3>DELETE<\/h3>\n<p>DELETE\u306f\u3001\u30c7\u30fc\u30bf\u306e\u524a\u9664\u3067\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>WHERE\u6761\u4ef6\u3092\u3064\u3051\u306a\u3044\u3068\u3001\u30c7\u30fc\u30bf\u304c\u5168\u4ef6\u524a\u9664\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u6c17\u3092\u3064\u3051\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"show-lang:2 lang:mysql decode:true\">\/* \u57fa\u672c\u7684\u306a\u66f8\u304d\u65b9 *\/\r\nDELETE\r\nFROM \u30c6\u30fc\u30d6\u30eb\u540d\r\n    (WHERE \u6761\u4ef6\u6587)\r\n\r\n\/* \u4f8b \u90fd\u9053\u5e9c\u770c\u30b3\u30fc\u30c9\u304c47\u306e\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3059\u308b *\/\r\nDELETE\r\nFROM \u90fd\u9053\u5e9c\u770c\r\nWHERE \u90fd\u9053\u5e9c\u770c\u30b3\u30fc\u30c9=47;<\/pre>\n<h3>INSERT<\/h3>\n<p>INSERT\u306f\u3001\u30c7\u30fc\u30bf\u306e\u8ffd\u52a0\u3067\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"show-lang:2 lang:mysql decode:true\">\/* \u5168\u5217\u306b\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3059\u308b\u5834\u5408 *\/\r\nINSERT INTO \u30c6\u30fc\u30d6\u30eb\u540d\r\nVALUES (\u50241,\u50242,\u2026)\r\n\r\n\/* \u4f8b \u90fd\u9053\u5e9c\u770c\u304c47\u306e\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3059\u308b *\/\r\nINSERT INTO \u90fd\u9053\u5e9c\u770c\r\n    VALUES (47,'\u6c96\u7e04\u770c');\r\n\r\n\/* \u5217\u6307\u5b9a\u3057\u3066\u8ffd\u52a0\u3059\u308b\u5834\u5408 *\/\r\nINSERT INTO \u30c6\u30fc\u30d6\u30eb\u540d\r\n    (\u5217\u540d1,\u5217\u540d2,\u2026)\r\n    VALUES (\u50241,\u50242,\u2026)\r\n\r\n\/* \u4f8b \u90fd\u9053\u5e9c\u770c\u304c47\u306e\u30c7\u30fc\u30bf\u3092\u5217\u6307\u5b9a\u3057\u3066\u8ffd\u52a0\u3059\u308b *\/ \r\nINSERT INTO \u90fd\u9053\u5e9c\u770c\r\n    (\u90fd\u9053\u5e9c\u770c\u30b3\u30fc\u30c9,\u90fd\u9053\u5e9c\u770c\u540d)\r\n    VALUES (47,'\u6c96\u7e04\u770c');<\/pre>\n<h2>\u30c7\u30fc\u30bf\u306e\u7d5e\u308a\u8fbc\u307f\u306fWHERE<\/h2>\n<p>\u5bfe\u8c61\u30c7\u30fc\u30bf\u3092\u7d5e\u308a\u8fbc\u307f\u305f\u3044\u5834\u5408\u306f\u3001WHERE\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>WHERE\u3067\u306f\u3001\u3055\u307e\u3056\u307e\u306a\u6f14\u7b97\u5b50\u3092\u5229\u7528\u3057\u3066\u691c\u7d22\u3057\u307e\u3059\u3002<\/p>\n<p>SELECT,UPDATE,DELETE\u3067\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<h3>\u6f14\u7b97\u5b50<\/h3>\n<h4>\u6bd4\u8f03\u6f14\u7b97\u5b50<\/h4>\n<p>\u6bd4\u8f03\u6f14\u7b97\u5b50\u306f\u3001\u4ee5\u4e0b\u306e\u6f14\u7b97\u5b50\u304c\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 33.3333%;\">=<\/td>\n<td style=\"width: 33.3333%;\">&lt;<\/td>\n<td style=\"width: 33.3333%;\">&gt;<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;\">&lt;=<\/td>\n<td style=\"width: 33.3333%;\">&gt;=<\/td>\n<td style=\"width: 33.3333%;\">&lt;&gt;<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;\">IS NULL<\/td>\n<td style=\"width: 33.3333%;\">LIKE<\/td>\n<td style=\"width: 33.3333%;\">BETWEEN \u958b\u59cb\u5024 AND \u7d42\u4e86\u5024<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;\">IN (\u50241,\u50242,\u2026)<\/td>\n<td style=\"width: 33.3333%;\">ANY (\u50241,\u50242,\u2026)<\/td>\n<td style=\"width: 33.3333%;\">ALL (\u50241,\u50242,\u2026)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u8ad6\u7406\u6f14\u7b97\u5b50<\/h4>\n<p>\u8ad6\u7406\u6f14\u7b97\u5b50\u306f\u30013\u3064\u306e\u6f14\u7b97\u5b50\u304c\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 33.3333%;\">AND<\/td>\n<td style=\"width: 33.3333%;\">OR<\/td>\n<td style=\"width: 33.3333%;\">NOT<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8ad6\u7406\u6f14\u7b97\u5b50\u306e\u512a\u5148\u9806\u4f4d\u306f\u3001NOT &gt; AND &gt; OR<\/p>\n<h4>NULL\u306e\u5224\u5b9a<\/h4>\n<p>NULL\u306e\u5224\u5b9a\u306f\u30012\u901a\u308a\u306e\u5224\u5b9a\u304c\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 50%;\">IS NULL<\/td>\n<td style=\"width: 50%;\">IS NOT NULL<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u691c\u7d22\u7d50\u679c\u3092\u52a0\u5de5\u3059\u308b<\/h2>\n<p>\u691c\u7d22\u3057\u305f\u7d50\u679c\u3092\u3001\u308f\u304b\u308a\u3084\u3059\u304f\u52a0\u5de5\u3057\u305f\u3044\u3068\u304d\u306b\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u691c\u7d22\u7d50\u679c\u3092\u4e26\u3079\u66ff\u3048\u305f\u308a\u3001\u8907\u6570\u306e\u691c\u7d22\u7d50\u679c\u3092\u8db3\u3057\u5408\u308f\u305b\u305f\u308a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>DISTINCT<\/h3>\n<p>\u30c7\u30fc\u30bf\u306e\u91cd\u8907\u3092\u524a\u9664\u3059\u308b\u3068\u304d\u306b\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">SELECT DISTINCT *\r\nFROM \u30c6\u30fc\u30d6\u30eb\u540d;\r\n\r\nSELECT DISTINCT \u5217\u540d1,\u5217\u540d2,\u2026\r\nFROM \u30c6\u30fc\u30d6\u30eb\u540d;<\/pre>\n<h3>ORDER BY<\/h3>\n<p>\u6307\u5b9a\u3057\u305f\u5217\u3092\u57fa\u6e96\u306b\u4e26\u3073\u66ff\u3048\u308b\u3068\u304d\u306b\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"show-lang:2 lang:mysql decode:true \">\/* \u6607\u9806(ASC) *\/\r\nSELECT DISTINCT \u5217\u540d1,\u5217\u540d2,\u2026\r\nFROM \u30c6\u30fc\u30d6\u30eb\u540d\r\nORDER BY \u5217\u540d ASC;\r\n\r\n\/* \u7701\u7565\u3057\u305f\u5834\u5408\u306fASC\u3068\u540c\u3058 *\/\r\nSELECT DISTINCT \u5217\u540d1,\u5217\u540d2,\u2026\r\nFROM \u30c6\u30fc\u30d6\u30eb\u540d\r\nORDER BY \u5217\u540d;\r\n\r\n\/* \u964d\u9806(DESC) *\/\r\nSELECT DISTINCT \u5217\u540d1,\u5217\u540d2,\u2026\r\nFROM \u30c6\u30fc\u30d6\u30eb\u540d\r\nORDER BY \u5217\u540d DESC;\r\n\r\n\/* \u8907\u6570\u306e\u5217\u3092\u4e26\u3073\u5909\u3048 *\/\r\nSELECT DISTINCT \u5217\u540d1,\u5217\u540d2,\u2026\r\nFROM \u30c6\u30fc\u30d6\u30eb\u540d\r\nORDER BY \u5217\u540d DESC, \u5217\u540d ASC,\u2026;<\/pre>\n<h3>UNION<\/h3>\n<p>\u30c6\u30fc\u30d6\u30eb\u540d1\u3068\u30c6\u30fc\u30d6\u30eb\u540d2\u3092\u8db3\u3057\u5408\u308f\u305b\u308b\u3068\u304d\u306b\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u6700\u5f8c\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u4e26\u3073\u66ff\u3048\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"show-lang:2 lang:mysql decode:true\">\/* UNION\u306e\u4f7f\u3044\u65b9 *\/\r\nSELECT * FROM \u30c6\u30fc\u30d6\u30eb\u540d1\r\nUNION\r\nSELECT * FROM \u30c6\u30fc\u30d6\u30eb\u540d2;\r\n\r\n\/* ORDER BY\u3092\u542b\u3080UNION\u306e\u4f7f\u3044\u65b9 *\/\r\nSELECT * FROM \u30c6\u30fc\u30d6\u30eb\u540d1\r\nUNION\r\nSELECT * FROM \u30c6\u30fc\u30d6\u30eb\u540d2\r\nORDER BY \u5217\u540d1,\u5217\u540d2 DESC;<\/pre>\n<h3>EXCEPT<\/h3>\n<p>\u30c6\u30fc\u30d6\u30eb\u540d1\u304b\u3089\u30c6\u30fc\u30d6\u30eb\u540d2\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u9664\u304d\u305f\u3044\u3068\u304d\u306b\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"show-lang:2 lang:mysql decode:true \">\/* EXCEPT\u306e\u4f7f\u3044\u65b9 *\/\r\nSELECT * FROM \u30c6\u30fc\u30d6\u30eb\u540d1\r\nEXCEPT\r\nSELECT * FROM \u30c6\u30fc\u30d6\u30eb\u540d2;<\/pre>\n<h3>INTERSECT<\/h3>\n<p>\u30c6\u30fc\u30d6\u30eb\u540d1\u3068\u30c6\u30fc\u30d6\u30eb\u540d2\u304c\u91cd\u8907\u3059\u308b\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u305f\u3044\u3068\u304d\u306b\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"show-lang:2 lang:mysql decode:true\">\/* INTERSECT\u306e\u4f7f\u3044\u65b9 *\/\r\nSELECT * FROM \u30c6\u30fc\u30d6\u30eb\u540d1\r\nINTERSECT\r\nSELECT * FROM \u30c6\u30fc\u30d6\u30eb\u540d2;<\/pre>\n<h3>OFFSET, FETCH(SQL Server)<\/h3>\n<p>\u5148\u982d\u3088\u308am+1\u756a\u76ee\u304b\u3089n\u6570\u4ef6\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u305f\u3044\u3068\u304d\u306b\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"show-lang:2 lang:mysql decode:true\">\/* m\u884c\u98db\u3070\u3057\u3066m+1\u884c\u76ee\u304b\u3089n\u884c\u5206\u3092\u53d6\u5f97\u3059\u308b *\/\r\nSELECT *\r\nFROM \u30c6\u30fc\u30d6\u30eb\u540d1\r\nOFFSET m ROWS \r\nFETCH NEXT n ROWS ONLY;<\/pre>\n<h2>\u96c6\u8a08\u3068\u30b0\u30eb\u30fc\u30d7\u5316<\/h2>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3067\u306f\u3001SELECT\u3092\u5229\u7528\u3057\u306a\u304c\u3089\u30c7\u30fc\u30bf\u3092\u96c6\u8a08\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u96c6\u8a08\u3067\u5229\u7528\u3059\u308b\u95a2\u6570<\/h3>\n<p>\u96c6\u8a08\u306b\u3064\u3044\u3066\u306f\u3001\u5217\u540d\u306e\u5024\u304c\u6570\u5024\u3067\u3042\u308c\u3070\u3001\u4ee5\u4e0b\u306e5\u3064\u306e\u95a2\u6570\u3092\u5229\u7528\u3057\u3066\u96c6\u8a08\u3067\u304d\u307e\u3059\u3002<\/p>\n<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td style=\"width: 33.3333%;\">COUNT<\/td>\n<td style=\"width: 33.3333%;\">\u9078\u629e\u3057\u305f\u30c7\u30fc\u30bf\u3092\u30ab\u30a6\u30f3\u30c8\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;\">SUM<\/td>\n<td style=\"width: 33.3333%;\">\u9078\u629e\u3057\u305f\u30c7\u30fc\u30bf\u306e\u5217\u540d\u304b\u3089\u5408\u8a08\u3092\u6c42\u3081\u307e\u3059\u3002\u6587\u5b57\u5217\u3084\u65e5\u4ed8\u306f\u4e0d\u53ef\u3067\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;\">MAX<\/td>\n<td style=\"width: 33.3333%;\">\u9078\u629e\u3057\u305f\u30c7\u30fc\u30bf\u306e\u5217\u540d\u306e\u3046\u3061\u6700\u5927\u5024\u3092\u6c42\u3081\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;\">MIN<\/td>\n<td style=\"width: 33.3333%;\">\u9078\u629e\u3057\u305f\u30c7\u30fc\u30bf\u306e\u5217\u540d\u306e\u3046\u3061\u3001\u6700\u5c0f\u5024\u3092\u6c42\u3081\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;\">AVG<\/td>\n<td style=\"width: 33.3333%;\">\u9078\u629e\u3057\u305f\u30c7\u30fc\u30bf\u306e\u5217\u540d\u306e\u5e73\u5747\u3092\u6c42\u3081\u307e\u3059\u3002\u6587\u5b57\u5217\u3084\u65e5\u4ed8\u306f\u4e0d\u53ef\u3067\u3059\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre class=\"show-lang:2 lang:mysql decode:true \">SELECT COUNT(*) AS \u884c\u6570\r\nFROM \u30c6\u30fc\u30d6\u30eb\r\n(WHERE \u6761\u4ef6\u6587);\r\n\r\nSELECT\r\n    SUM(\u5217\u540d1) AS \u5217\u540d1\u306e\u5408\u8a08 \r\n    MAX(\u5217\u540d1) AS \u5217\u540d1\u306e\u6700\u5927 \r\n    MIN(\u5217\u540d1) AS \u5217\u540d1\u306e\u6700\u5c0f \r\n    AVG(\u5217\u540d1) AS \u5217\u540d1\u306e\u5e73\u5747 \r\nFROM \u30c6\u30fc\u30d6\u30eb\r\n(WHERE \u6761\u4ef6\u6587);<\/pre>\n<h3>\u96c6\u8a08\u306e\u30b0\u30eb\u30fc\u30d7\u5316<\/h3>\n<p>\u96c6\u8a08\u3059\u308b\u969b\u3001\u5217\u540d\u3092\u57fa\u6e96\u3068\u3057\u3066\u30b0\u30eb\u30fc\u30d7\u5316\u3057\u3066\u96c6\u8a08\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u30b0\u30eb\u30fc\u30d7\u5316\u3057\u3066\u96c6\u8a08\u3059\u308b\u306b\u306f\u3001GROUP BY\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"show-lang:2 lang:mysql decode:true \">SELECT \u96c6\u8a08\u95a2\u6570\r\nFROM \u30c6\u30fc\u30d6\u30eb\u540d\r\n(WHERE \u6761\u4ef6\u6587)\r\nGROUP BY \u30b0\u30eb\u30fc\u30d7\u5316\u5bfe\u8c61\u5217\u540d;\r\n\r\n\/* \u4f8b.\u90fd\u9053\u5e9c\u770c\u5225\u306b\u4eba\u53e3\u3092\u96c6\u8a08\u3059\u308b *\/\r\nSELECT \u90fd\u9053\u5e9c\u770c\u540d,SUM(\u4eba\u53e3)\r\nFROM \u90fd\u9053\u5e9c\u770c\r\nGROUP BY \u90fd\u9053\u5e9c\u770c\u30b3\u30fc\u30c9;<\/pre>\n<h3>\u96c6\u8a08\u5f8c\u306e\u7d5e\u308a\u8fbc\u307f(HAVING)<\/h3>\n<p>\u96c6\u8a08\u95a2\u6570\u3092\u5229\u7528\u3057\u3066\u96c6\u8a08\u304c\u7d42\u308f\u3063\u305f\u3042\u3068\u306b\u7d5e\u308a\u8fbc\u307f\u3092\u884c\u3046\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u7d5e\u308a\u8fbc\u307f\u306f\u3001HAVING\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"show-lang:2 lang:mysql decode:true \">SELECT \u96c6\u8a08\u95a2\u6570\r\nFROM \u30c6\u30fc\u30d6\u30eb\u540d\r\n(WHERE \u6761\u4ef6\u6587)\r\nGROUP BY \u30b0\u30eb\u30fc\u30d7\u5316\u5bfe\u8c61\u5217\u540d\r\nHAVING \u96c6\u8a08\u7d50\u679c\u306e\u7d5e\u308a\u8fbc\u307f;\r\n\r\n\/* \u4f8b.\u4eba\u53e3\u304c200\u4e07\u4eba\u4ee5\u4e0a\u306e\u90fd\u9053\u5e9c\u770c\u3092\u6607\u9806\u3067\u62bd\u51fa\u3059\u308b *\/\r\nSELECT \u90fd\u9053\u5e9c\u770c\u540d,SUM(\u4eba\u53e3)\r\nFROM \u90fd\u9053\u5e9c\u770c\r\nGROUP BY \u90fd\u9053\u5e9c\u770c\u30b3\u30fc\u30c9\r\nHAVING SUM(\u4eba\u53e3) &gt;= 2000000;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL\u3068\u306f SQL\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u7ba1\u7406\u30b7\u30b9\u30c6\u30e0(RDBMS)\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u5b9a\u7fa9\u3084\u64cd\u4f5c\u3092\u884c\u3046\u305f\u3081\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u8a00\u8a9e\u3067\u3059\u3002 \u307e\u305f\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3068\u4f75\u7528\u3057\u3066\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u305f\u3081\u306b\u306f\u5229\u7528\u3055\u308c\u307e\u3059\u3002 SQL\u306e\u6a19\u6e96\u898f\u683c\u306f\u3001ANSI\uff08\u7c73\u56fd\u898f\u683c\u5354\u4f1a\uff09\u3084ISO\uff08\u56fd\u969b\u6a19\u6e96\u5316\u6a5f\u69cb\uff09\u3068\u3044\u3063\u305f\u6a19\u6e96\u5316\u56e3\u4f53\u306b\u3088\u3063\u3066\u6a19\u6e96\u5316\u3055\u308c\u3066\u304a\u308a\u3001\u4e00\u5ea6\u5b66\u7fd2\u3059\u308c\u3070\u3042\u3089\u3086\u308b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3067\u307b\u307c\u540c\u3058\u3088\u3046\u306a\u64cd\u4f5c\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002 SQL [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1402,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[291],"tags":[267,294,293,265,266,292],"class_list":["post-1368","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql","tag-delete","tag-insert","tag-select","tag-sql","tag-update","tag-292"],"_links":{"self":[{"href":"https:\/\/sunafukin.jp\/index.php?rest_route=\/wp\/v2\/posts\/1368"}],"collection":[{"href":"https:\/\/sunafukin.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sunafukin.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sunafukin.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sunafukin.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1368"}],"version-history":[{"count":32,"href":"https:\/\/sunafukin.jp\/index.php?rest_route=\/wp\/v2\/posts\/1368\/revisions"}],"predecessor-version":[{"id":1404,"href":"https:\/\/sunafukin.jp\/index.php?rest_route=\/wp\/v2\/posts\/1368\/revisions\/1404"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sunafukin.jp\/index.php?rest_route=\/wp\/v2\/media\/1402"}],"wp:attachment":[{"href":"https:\/\/sunafukin.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sunafukin.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sunafukin.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}