{"id":6077,"date":"2025-09-28T00:57:27","date_gmt":"2025-09-27T15:57:27","guid":{"rendered":"https:\/\/sky-peace.net\/?p=6077"},"modified":"2025-09-28T00:57:27","modified_gmt":"2025-09-27T15:57:27","slug":"sql-cube","status":"publish","type":"post","link":"https:\/\/sky-peace.net\/certified\/sql-cube\/","title":{"rendered":"\u3010SQL\u5165\u9580\u3011GROUPING SETS, ROLLUP, CUBE\u306e\u9055\u3044\u3068\u4f7f\u3044\u65b9\u3092\u5fb9\u5e95\u89e3\u8aac"},"content":{"rendered":"<p>SQL\u3067\u30c7\u30fc\u30bf\u3092\u96c6\u8a08\u3059\u308b\u969b\u3001<code>GROUP BY<\/code>\u53e5\u306f\u975e\u5e38\u306b\u5f37\u529b\u306a\u6b66\u5668\u3067\u3059\u3002\u3057\u304b\u3057\u3001\u300c\u90e8\u7f72\u3054\u3068\u306e\u58f2\u4e0a\u300d\u300c\u5f79\u8077\u3054\u3068\u306e\u58f2\u4e0a\u300d\u300c\u5168\u793e\u306e\u7dcf\u58f2\u4e0a\u300d\u3068\u3044\u3063\u305f\u8907\u6570\u306e\u96c6\u8a08\u3092\u4e00\u5ea6\u306b\u884c\u3044\u305f\u3044\u5834\u5408\u3001\u3069\u3046\u3057\u3066\u3044\u307e\u3059\u304b\uff1f \u304a\u305d\u3089\u304f\u3001\u305d\u308c\u305e\u308c\u306e\u96c6\u8a08\u30af\u30a8\u30ea\u3092\u66f8\u3044\u3066 <code>UNION ALL<\/code> \u3067\u7d50\u5408\u3059\u308b\u3001\u3068\u3044\u3063\u305f\u9762\u5012\u306a\u624b\u9806\u3092\u8e0f\u3093\u3067\u3044\u308b\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002\u3053\u306e\u65b9\u6cd5\u3067\u306fSQL\u304c\u8907\u96d1\u3067\u9577\u304f\u306a\u308a\u3001\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u6027\u3082\u4f4e\u4e0b\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u5b9f\u306f\u3001SQL\u306b\u306f\u3053\u3046\u3057\u305f\u8ab2\u984c\u3092\u30b9\u30de\u30fc\u30c8\u306b\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306e\u5f37\u529b\u306a\u6a5f\u80fd\u304c\u5099\u308f\u3063\u3066\u3044\u307e\u3059\u3002\u305d\u308c\u304c\u3001<strong><code>GROUPING SETS<\/code>\u3001<code>ROLLUP<\/code>\u3001<code>CUBE<\/code><\/strong> \u3068\u3044\u3063\u305f\u62e1\u5f35<code>GROUP BY<\/code>\u53e5\u3067\u3059\u3002\u3053\u308c\u3089\u306f\u300c\u30b0\u30eb\u30fc\u30d7\u5316\u30bb\u30c3\u30c8\u300d\u3068\u3082\u547c\u3070\u308c\u3001<strong>1\u3064\u306e\u30af\u30a8\u30ea\u3067\u8907\u6570\u30d1\u30bf\u30fc\u30f3\u306e\u96c6\u8a08\u3092\u4e00\u5ea6\u306b\u53d6\u5f97\u3067\u304d\u308b<\/strong>\u305f\u3081\u3001\u30c7\u30fc\u30bf\u5206\u6790\u3084\u30ec\u30dd\u30fc\u30c6\u30a3\u30f3\u30b0\u306e\u52b9\u7387\u3092\u5287\u7684\u306b\u5411\u4e0a\u3055\u305b\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001<code>GROUPING SETS<\/code>\u3001<code>ROLLUP<\/code>\u3001<code>CUBE<\/code>\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u304b\u3089\u3001\u305d\u308c\u305e\u308c\u306e\u9055\u3044\u3001\u305d\u3057\u3066\u3069\u306e\u3088\u3046\u306a\u5834\u9762\u3067\u5f79\u7acb\u3064\u306e\u304b\u307e\u3067\u3092\u3001\u5177\u4f53\u7684\u306a\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf\u3068\u30b3\u30fc\u30c9\u3001\u56f3\u89e3\u3092\u4ea4\u3048\u306a\u304c\u3089\u7db2\u7f85\u7684\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30b9\u30da\u30b7\u30e3\u30ea\u30b9\u30c8\u8a66\u9a13\u306a\u3069\u306e\u8cc7\u683c\u5bfe\u7b56\u306f\u3082\u3061\u308d\u3093\u3001\u5b9f\u52d9\u3067\u306e\u30c7\u30fc\u30bf\u6d3b\u7528\u30b9\u30ad\u30eb\u3092\u4e00\u6bb5\u968e\u30ec\u30d9\u30eb\u30a2\u30c3\u30d7\u3055\u305b\u305f\u3044\u65b9\u3082\u3001\u305c\u3072\u6700\u5f8c\u307e\u3067\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u307e\u305a\u306f\u57fa\u672c\u304b\u3089\u2502GROUP BY\u53e5\u306e\u8ab2\u984c\u3068\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf<\/h2>\n<p><code>GROUPING SETS<\/code>\u306a\u3069\u306e\u9ad8\u5ea6\u306a\u6a5f\u80fd\u3092\u898b\u3066\u3044\u304f\u524d\u306b\u3001\u307e\u305a\u306f\u57fa\u672c\u3068\u306a\u308b<code>GROUP BY<\/code>\u53e5\u306e\u5f79\u5272\u3068\u3001\u8907\u6570\u306e\u96c6\u8a08\u3092\u884c\u304a\u3046\u3068\u3057\u305f\u969b\u306e\u8ab2\u984c\u306b\u3064\u3044\u3066\u7c21\u5358\u306b\u304a\u3055\u3089\u3044\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3><code>GROUP BY<\/code>\u53e5\u3068\u8907\u6570\u96c6\u8a08\u306e\u8ab2\u984c<\/h3>\n<p><code>GROUP BY<\/code>\u306f\u3001\u6307\u5b9a\u3057\u305f\u5217\uff08\u4f8b\uff1a\u90e8\u7f72\u540d\uff09\u306e\u5024\u304c\u540c\u3058\u884c\u3092\u4e00\u3064\u306e\u30b0\u30eb\u30fc\u30d7\u306b\u307e\u3068\u3081\u3001<code>SUM()<\/code>\u3084<code>COUNT()<\/code>\u3068\u3044\u3063\u305f\u96c6\u8a08\u95a2\u6570\u3092\u9069\u7528\u3059\u308b\u305f\u3081\u306e\u53e5\u3067\u3059\u3002\u3057\u304b\u3057\u3001\u4f8b\u3048\u3070\u300c\u2460\u90e8\u7f72\u3054\u3068\u306e\u5408\u8a08\u7d66\u4e0e\u300d\u3068\u300c\u2461\u5f79\u8077\u3054\u3068\u306e\u5408\u8a08\u7d66\u4e0e\u300d\u3092\u540c\u6642\u306b\u898b\u305f\u3044\u5834\u5408\u3001\u4e00\u3064\u306e<code>GROUP BY<\/code>\u53e5\u3067\u3053\u308c\u3092\u8868\u73fe\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u5f93\u6765\u306e\u65b9\u6cd5\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u305d\u308c\u305e\u308c\u306e\u96c6\u8a08\u30af\u30a8\u30ea\u3092\u66f8\u304d\u3001<code>UNION ALL<\/code>\u3067\u7d50\u5408\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><strong>\u3010<code>UNION ALL<\/code>\u3092\u4f7f\u3063\u305f\u8907\u6570\u30d1\u30bf\u30fc\u30f3\u306e\u96c6\u8a08\u4f8b\u3011<\/strong><\/p>\n<pre><code>\n-- \u2460 \u90e8\u7f72\u3054\u3068\u306e\u5408\u8a08\u7d66\u4e0e\nSELECT\n  department,\n  NULL AS position,\n  SUM(salary) AS total_salary\nFROM\n  employees\nGROUP BY\n  department\n\nUNION ALL\n\n-- \u2461 \u5f79\u8077\u3054\u3068\u306e\u5408\u8a08\u7d66\u4e0e\nSELECT\n  NULL AS department,\n  position,\n  SUM(salary) AS total_salary\nFROM\n  employees\nGROUP BY\n  position;\n<\/code><\/pre>\n<p>\u3053\u306e\u65b9\u6cd5\u3067\u3082\u7d50\u679c\u306f\u5f97\u3089\u308c\u307e\u3059\u304c\u3001\u30af\u30a8\u30ea\u304c\u5197\u9577\u306b\u306a\u308a\u3001\u96c6\u8a08\u30d1\u30bf\u30fc\u30f3\u304c\u5897\u3048\u308b\u307b\u3069SQL\u306f\u8907\u96d1\u5316\u3057\u3066\u3044\u304d\u307e\u3059\u3002\u3053\u306e\u8ab2\u984c\u3092\u89e3\u6c7a\u3059\u308b\u306e\u304c\u3001\u3053\u308c\u304b\u3089\u5b66\u3076\u30b0\u30eb\u30fc\u30d7\u5316\u30bb\u30c3\u30c8\u3067\u3059\u3002<\/p>\n<h3>\u4eca\u56de\u4f7f\u7528\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u30c7\u30fc\u30bf<\/h3>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u300c\u5f93\u696d\u54e1\uff08employees\uff09\u300d\u30c6\u30fc\u30d6\u30eb\u3092\u4f8b\u306b\u89e3\u8aac\u3092\u9032\u3081\u307e\u3059\u3002\u90e8\u7f72\uff08department\uff09\u3001\u5f79\u8077\uff08position\uff09\u3001\u6027\u5225\uff08gender\uff09\u3001\u7d66\u4e0e\uff08salary\uff09\u3068\u3044\u3063\u305f\u30ab\u30e9\u30e0\u3092\u6301\u3064\u30b7\u30f3\u30d7\u30eb\u306a\u30c6\u30fc\u30d6\u30eb\u3067\u3059\u3002<\/p>\n<p><strong>\u3010employees \u30c6\u30fc\u30d6\u30eb\u3011<\/strong><\/p>\n<table border=\"1\" style=\"width:100%; border-collapse: collapse;\">\n<thead>\n<tr>\n<th style=\"padding: 8px; text-align: left;\">id<\/th>\n<th style=\"padding: 8px; text-align: left;\">department<\/th>\n<th style=\"padding: 8px; text-align: left;\">position<\/th>\n<th style=\"padding: 8px; text-align: left;\">gender<\/th>\n<th style=\"padding: 8px; text-align: left;\">salary<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 8px;\">1<\/td>\n<td style=\"padding: 8px;\">\u55b6\u696d\u90e8<\/td>\n<td style=\"padding: 8px;\">\u90e8\u9577<\/td>\n<td style=\"padding: 8px;\">\u7537\u6027<\/td>\n<td style=\"padding: 8px;\">800<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">2<\/td>\n<td style=\"padding: 8px;\">\u55b6\u696d\u90e8<\/td>\n<td style=\"padding: 8px;\">\u8ab2\u9577<\/td>\n<td style=\"padding: 8px;\">\u5973\u6027<\/td>\n<td style=\"padding: 8px;\">600<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">3<\/td>\n<td style=\"padding: 8px;\">\u55b6\u696d\u90e8<\/td>\n<td style=\"padding: 8px;\">\u4e00\u822c<\/td>\n<td style=\"padding: 8px;\">\u7537\u6027<\/td>\n<td style=\"padding: 8px;\">400<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">4<\/td>\n<td style=\"padding: 8px;\">\u55b6\u696d\u90e8<\/td>\n<td style=\"padding: 8px;\">\u4e00\u822c<\/td>\n<td style=\"padding: 8px;\">\u5973\u6027<\/td>\n<td style=\"padding: 8px;\">400<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">5<\/td>\n<td style=\"padding: 8px;\">\u958b\u767a\u90e8<\/td>\n<td style=\"padding: 8px;\">\u90e8\u9577<\/td>\n<td style=\"padding: 8px;\">\u7537\u6027<\/td>\n<td style=\"padding: 8px;\">850<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">6<\/td>\n<td style=\"padding: 8px;\">\u958b\u767a\u90e8<\/td>\n<td style=\"padding: 8px;\">\u8ab2\u9577<\/td>\n<td style=\"padding: 8px;\">\u7537\u6027<\/td>\n<td style=\"padding: 8px;\">650<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">7<\/td>\n<td style=\"padding: 8px;\">\u958b\u767a\u90e8<\/td>\n<td style=\"padding: 8px;\">\u4e00\u822c<\/td>\n<td style=\"padding: 8px;\">\u5973\u6027<\/td>\n<td style=\"padding: 8px;\">450<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">8<\/td>\n<td style=\"padding: 8px;\">\u4eba\u4e8b\u90e8<\/td>\n<td style=\"padding: 8px;\">\u8ab2\u9577<\/td>\n<td style=\"padding: 8px;\">\u5973\u6027<\/td>\n<td style=\"padding: 8px;\">580<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">9<\/td>\n<td style=\"padding: 8px;\">\u4eba\u4e8b\u90e8<\/td>\n<td style=\"padding: 8px;\">\u4e00\u822c<\/td>\n<td style=\"padding: 8px;\">\u7537\u6027<\/td>\n<td style=\"padding: 8px;\">380<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3053\u306e\u30c7\u30fc\u30bf\u3092\u5143\u306b\u3001<code>GROUPING SETS<\/code>\u3001<code>ROLLUP<\/code>\u3001<code>CUBE<\/code>\u304c\u3069\u306e\u3088\u3046\u306b\u52d5\u4f5c\u3059\u308b\u306e\u304b\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<hr>\n<h2>GROUPING SETS\u53e5\u306eSQL\u2502\u6307\u5b9a\u3057\u305f\u7d44\u307f\u5408\u308f\u305b\u3092\u4e00\u5ea6\u306b\u96c6\u8a08<\/h2>\n<p><code>UNION ALL<\/code>\u306e\u5197\u9577\u3055\u3092\u89e3\u6d88\u3059\u308b\u6700\u521d\u306e\u5207\u308a\u672d\u304c<code>GROUPING SETS<\/code>\u3067\u3059\u3002\u3053\u308c\u306f\u3001<strong>\u96c6\u8a08\u3057\u305f\u3044\u30b0\u30eb\u30fc\u30d7\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u62ec\u5f27 <code>()<\/code> \u3067\u81ea\u7531\u306b\u6307\u5b9a\u3067\u304d\u308b<\/strong>\u6a5f\u80fd\u3067\u3059\u3002\u307e\u308b\u3067\u30ec\u30b9\u30c8\u30e9\u30f3\u3067\u30a2\u30e9\u30ab\u30eb\u30c8\u30e1\u30cb\u30e5\u30fc\u3092\u6ce8\u6587\u3059\u308b\u3088\u3046\u306b\u3001\u6b32\u3057\u3044\u96c6\u8a08\u30d1\u30bf\u30fc\u30f3\u3060\u3051\u3092\u30d4\u30f3\u30dd\u30a4\u30f3\u30c8\u3067\u8981\u6c42\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3068SQL\u69cb\u6587<\/h3>\n<p><code>GROUPING SETS<\/code>\u306f<code>GROUP BY<\/code>\u53e5\u306e\u4e2d\u3067\u4f7f\u7528\u3057\u307e\u3059\u3002\u57fa\u672c\u7684\u306a\u69cb\u6587\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<pre><code>\nSELECT\n  column1,\n  column2,\n  \u96c6\u8a08\u95a2\u6570(column3)\nFROM\n  table_name\nGROUP BY\n  GROUPING SETS ( (column1), (column2), ... );\n<\/code><\/pre>\n<p>\u5148\u307b\u3069\u306e<code>UNION ALL<\/code>\u3067\u5b9f\u73fe\u3057\u305f\u300c\u2460\u90e8\u7f72\u3054\u3068\u306e\u5408\u8a08\u7d66\u4e0e\u300d\u3068\u300c\u2461\u5f79\u8077\u3054\u3068\u306e\u5408\u8a08\u7d66\u4e0e\u300d\u306f\u3001<code>GROUPING SETS<\/code>\u3092\u4f7f\u3048\u3070\u6b21\u306e\u4e00\u3064\u306eSQL\u3067\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><strong>\u3010GROUPING SETS \u3092\u4f7f\u3063\u305fSQL\u4f8b\u3011<\/strong><\/p>\n<pre><code>\nSELECT\n  department,\n  position,\n  SUM(salary) AS total_salary\nFROM\n  employees\nGROUP BY\n  GROUPING SETS ( (department), (position) );\n<\/code><\/pre>\n<h3>\u5b9f\u884c\u7d50\u679c\u3068NULL\u306e\u610f\u5473<\/h3>\n<p>\u4e0a\u8a18\u306eSQL\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<code>UNION ALL<\/code>\u3092\u4f7f\u3063\u305f\u6642\u3068\u4f3c\u305f\u7d50\u679c\u304c\u3001\u3088\u308a\u30b7\u30f3\u30d7\u30eb\u306a\u30af\u30a8\u30ea\u3067\u5f97\u3089\u308c\u307e\u3057\u305f\u3002<\/p>\n<table border=\"1\" style=\"width:100%; border-collapse: collapse;\">\n<thead>\n<tr>\n<th style=\"padding: 8px; text-align: left;\">department<\/th>\n<th style=\"padding: 8px; text-align: left;\">position<\/th>\n<th style=\"padding: 8px; text-align: left;\">total_salary<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 8px;\">\u55b6\u696d\u90e8<\/td>\n<td style=\"padding: 8px;\">NULL<\/td>\n<td style=\"padding: 8px;\">2200<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u958b\u767a\u90e8<\/td>\n<td style=\"padding: 8px;\">NULL<\/td>\n<td style=\"padding: 8px;\">1950<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u4eba\u4e8b\u90e8<\/td>\n<td style=\"padding: 8px;\">NULL<\/td>\n<td style=\"padding: 8px;\">960<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">NULL<\/td>\n<td style=\"padding: 8px;\">\u90e8\u9577<\/td>\n<td style=\"padding: 8px;\">1650<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">NULL<\/td>\n<td style=\"padding: 8px;\">\u8ab2\u9577<\/td>\n<td style=\"padding: 8px;\">1830<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">NULL<\/td>\n<td style=\"padding: 8px;\">\u4e00\u822c<\/td>\n<td style=\"padding: 8px;\">1630<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3053\u3053\u3067\u6ce8\u76ee\u3059\u3079\u304d\u306f<code>NULL<\/code>\u306e\u5b58\u5728\u3067\u3059\u3002<br \/>\u3053\u306e<code>NULL<\/code>\u306f\u3001\u30c7\u30fc\u30bf\u304c\u5143\u3005<code>NULL<\/code>\u3067\u3042\u308b\u3068\u3044\u3046\u610f\u5473\u3067\u306f\u306a\u304f\u3001<strong>\u300c\u3053\u306e\u884c\u306f\u305d\u306e\u5217\u3067\u30b0\u30eb\u30fc\u30d7\u5316\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3088\u300d<\/strong>\u3068\u3044\u3046\u3053\u3068\u3092\u793a\u3059\u7279\u5225\u306a<code>NULL<\/code>\u3067\u3059\u3002\u4f8b\u3048\u3070\u3001<code>department<\/code>\u304c\u300c\u55b6\u696d\u90e8\u300d\u3067<code>position<\/code>\u304c<code>NULL<\/code>\u306e\u884c\u306f\u3001\u300c\u90e8\u7f72\u3054\u3068\u306b\u96c6\u8a08\u3057\u305f\u7d50\u679c\u300d\u3067\u3042\u308a\u3001\u5f79\u8077\u306f\u8003\u616e\u3057\u3066\u3044\u306a\u3044\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002<\/p>\n<h3>\u8907\u6570\u5217\u3084\u7dcf\u8a08\u306e\u7d44\u307f\u5408\u308f\u305b\u3082\u53ef\u80fd<\/h3>\n<p><code>GROUPING SETS<\/code>\u306e\u5f37\u529b\u306a\u70b9\u306f\u3001\u8907\u6570\u5217\u306e\u7d44\u307f\u5408\u308f\u305b\u3084\u3001\u5168\u30c7\u30fc\u30bf\u3092\u5bfe\u8c61\u3068\u3057\u305f\u7dcf\u8a08\uff08\u30b0\u30e9\u30f3\u30c9\u30c8\u30fc\u30bf\u30eb\uff09\u3082\u6307\u5b9a\u3067\u304d\u308b\u3053\u3068\u3067\u3059\u3002<\/p>\n<ul>\n<li><code>(department, position)<\/code>\uff1a\u90e8\u7f72\u3068\u5f79\u8077\u306e\u7d44\u307f\u5408\u308f\u305b\u3067\u96c6\u8a08<\/li>\n<li><code>()<\/code>\uff1a\u5168\u30c7\u30fc\u30bf\u30921\u3064\u306e\u30b0\u30eb\u30fc\u30d7\u3068\u3057\u3066\u96c6\u8a08\uff08\u7dcf\u8a08\uff09<\/li>\n<\/ul>\n<p>\u4f8b\u3048\u3070\u3001\u300c\u90e8\u7f72\u3054\u3068\u300d\u300c\u5f79\u8077\u3054\u3068\u300d\u300c\u90e8\u7f72\u3068\u5f79\u8077\u306e\u7d44\u307f\u5408\u308f\u305b\u3054\u3068\u300d\u300c\u5168\u4f53\u306e\u5408\u8a08\u300d\u306e4\u30d1\u30bf\u30fc\u30f3\u3092\u4e00\u5ea6\u306b\u53d6\u5f97\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre><code>\nSELECT\n  department,\n  position,\n  SUM(salary) AS total_salary\nFROM\n  employees\nGROUP BY\n  GROUPING SETS ( (department), (position), (department, position), () );\n<\/code><\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b<code>GROUPING SETS<\/code>\u306f\u3001\u958b\u767a\u8005\u304c\u5fc5\u8981\u3068\u3059\u308b\u96c6\u8a08\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u67d4\u8edf\u304b\u3064\u660e\u793a\u7684\u306b\u6307\u5b9a\u3067\u304d\u308b\u3001\u975e\u5e38\u306b\u4fbf\u5229\u306a\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<h2>ROLLUP\u306e\u4f7f\u3044\u65b9\u2502\u968e\u5c64\u7684\u306a\u5c0f\u8a08\u30fb\u5408\u8a08\u3092\u81ea\u52d5\u751f\u6210\u3059\u308bSQL<\/h2>\n<p><code>GROUPING SETS<\/code>\u304c\u30a2\u30e9\u30ab\u30eb\u30c8\u3060\u3068\u3057\u305f\u3089\u3001<code>ROLLUP<\/code>\u306f<strong>\u30b3\u30fc\u30b9\u6599\u7406\u306e\u3088\u3046\u306b\u6c7a\u307e\u3063\u305f\u30d1\u30bf\u30fc\u30f3\u306e\u96c6\u8a08\u3092\u81ea\u52d5\u7684\u306b\u884c\u3063\u3066\u304f\u308c\u308b<\/strong>\u6a5f\u80fd\u3067\u3059\u3002\u7279\u306b\u3001\u65e5\u6b21\u2192\u6708\u6b21\u2192\u5e74\u6b21\u306e\u3088\u3046\u306a\u968e\u5c64\u69cb\u9020\u3092\u6301\u3064\u30c7\u30fc\u30bf\u306e\u96c6\u8a08\uff08\u30c9\u30ea\u30eb\u30c0\u30a6\u30f3\u5206\u6790\uff09\u3067\u771f\u4fa1\u3092\u767a\u63ee\u3057\u307e\u3059\u3002<\/p>\n<p><code>ROLLUP<\/code>\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u5217\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u3001\u53f3\u5074\u306e\u5217\u304b\u3089\u4e00\u3064\u305a\u3064\u53d6\u308a\u9664\u304d\u306a\u304c\u3089\u96c6\u8a08\u30d1\u30bf\u30fc\u30f3\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<h3>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3068SQL\u69cb\u6587<\/h3>\n<p><code>ROLLUP(department, position)<\/code>\u3068\u6307\u5b9a\u3057\u305f\u5834\u5408\u3001\u5185\u90e8\u7684\u306b\u306f\u4ee5\u4e0b\u306e3\u3064\u306e\u96c6\u8a08\u30d1\u30bf\u30fc\u30f3\u3092\u751f\u6210\u3059\u308b<code>GROUPING SETS<\/code>\u3068\u7b49\u4fa1\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ol>\n<li><code>(department, position)<\/code> \uff1a\u90e8\u7f72\u3068\u5f79\u8077\u3054\u3068\u306e\u96c6\u8a08\uff08\u6700\u3082\u8a73\u7d30\uff09<\/li>\n<li><code>(department)<\/code> \uff1a\u90e8\u7f72\u3054\u3068\u306e\u5c0f\u8a08<\/li>\n<li><code>()<\/code> \uff1a\u5168\u4f53\u306e\u5408\u8a08\uff08\u30b0\u30e9\u30f3\u30c9\u30c8\u30fc\u30bf\u30eb\uff09<\/li>\n<\/ol>\n<p><strong>\u3010ROLLUP \u3092\u4f7f\u3063\u305fSQL\u4f8b\u3011<\/strong><\/p>\n<pre><code>\nSELECT\n  department,\n  position,\n  SUM(salary) AS total_salary\nFROM\n  employees\nGROUP BY\n  ROLLUP (department, position);\n<\/code><\/pre>\n<h3>\u5b9f\u884c\u7d50\u679c\u3068<code>GROUPING SETS<\/code>\u3068\u306e\u9055\u3044<\/h3>\n<p>\u4e0a\u8a18\u306eSQL\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<table border=\"1\" style=\"width:100%; border-collapse: collapse;\">\n<thead>\n<tr>\n<th style=\"padding: 8px; text-align: left;\">department<\/th>\n<th style=\"padding: 8px; text-align: left;\">position<\/th>\n<th style=\"padding: 8px; text-align: left;\">total_salary<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 8px;\">\u55b6\u696d\u90e8<\/td>\n<td style=\"padding: 8px;\">\u90e8\u9577<\/td>\n<td style=\"padding: 8px;\">800<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u55b6\u696d\u90e8<\/td>\n<td style=\"padding: 8px;\">\u8ab2\u9577<\/td>\n<td style=\"padding: 8px;\">600<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u55b6\u696d\u90e8<\/td>\n<td style=\"padding: 8px;\">\u4e00\u822c<\/td>\n<td style=\"padding: 8px;\">800<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong>\u55b6\u696d\u90e8<\/strong><\/td>\n<td style=\"padding: 8px;\"><strong>NULL<\/strong><\/td>\n<td style=\"padding: 8px;\"><strong>2200<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u958b\u767a\u90e8<\/td>\n<td style=\"padding: 8px;\">\u90e8\u9577<\/td>\n<td style=\"padding: 8px;\">850<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u958b\u767a\u90e8<\/td>\n<td style=\"padding: 8px;\">\u8ab2\u9577<\/td>\n<td style=\"padding: 8px;\">650<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u958b\u767a\u90e8<\/td>\n<td style=\"padding: 8px;\">\u4e00\u822c<\/td>\n<td style=\"padding: 8px;\">450<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong>\u958b\u767a\u90e8<\/strong><\/td>\n<td style=\"padding: 8px;\"><strong>NULL<\/strong><\/td>\n<td style=\"padding: 8px;\"><strong>1950<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u4eba\u4e8b\u90e8<\/td>\n<td style=\"padding: 8px;\">\u8ab2\u9577<\/td>\n<td style=\"padding: 8px;\">580<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u4eba\u4e8b\u90e8<\/td>\n<td style=\"padding: 8px;\">\u4e00\u822c<\/td>\n<td style=\"padding: 8px;\">380<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong>\u4eba\u4e8b\u90e8<\/strong><\/td>\n<td style=\"padding: 8px;\"><strong>NULL<\/strong><\/td>\n<td style=\"padding: 8px;\"><strong>960<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong>NULL<\/strong><\/td>\n<td style=\"padding: 8px;\"><strong>NULL<\/strong><\/td>\n<td style=\"padding: 8px;\"><strong>5110<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><code>GROUPING SETS<\/code>\u306e\u4f8b\u3068\u898b\u6bd4\u3079\u308b\u3068\u9055\u3044\u306f\u660e\u3089\u304b\u3067\u3059\u3002<code>ROLLUP<\/code>\u306f<code>(department, position)<\/code>\u306e\u8a73\u7d30\u306a\u96c6\u8a08\u306b\u52a0\u3048\u3066\u3001<strong>\u90e8\u7f72\u3054\u3068\u306e\u5c0f\u8a08<\/strong>\uff08<code>position<\/code>\u304c<code>NULL<\/code>\u306e\u884c\uff09\u3068\u3001<strong>\u5168\u4f53\u306e\u5408\u8a08<\/strong>\uff08<code>department<\/code>\u3068<code>position<\/code>\u304c\u4e21\u65b9<code>NULL<\/code>\u306e\u884c\uff09\u3092\u81ea\u52d5\u7684\u306b\u8ffd\u52a0\u3057\u3066\u304f\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><code>ROLLUP<\/code>\u306f\u6307\u5b9a\u3055\u308c\u305f\u5217\u306e\u968e\u5c64\u95a2\u4fc2\u3092\u610f\u8b58\u3057\u3001\u300c\u8a73\u7d30\u2192\u4e2d\u9805\u76ee\u2192\u5927\u9805\u76ee\u300d\u3078\u3068\u5dfb\u304d\u4e0a\u3052\u3066\u96c6\u8a08\uff08\u30ed\u30fc\u30eb\u30a2\u30c3\u30d7\uff09\u3057\u3066\u304f\u308c\u308b\u306e\u3067\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u96c6\u8a08\u30d1\u30bf\u30fc\u30f3\u3092\u4e00\u3064\u305a\u3064\u8a18\u8ff0\u3059\u308b\u624b\u9593\u304c\u7701\u3051\u3001\u30b3\u30fc\u30c9\u3082\u30b7\u30f3\u30d7\u30eb\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<hr>\n<h2>CUBE\u306e\u4f7f\u3044\u65b9\u2502\u5168\u30d1\u30bf\u30fc\u30f3\u306e\u30af\u30ed\u30b9\u96c6\u8a08\u3092\u7db2\u7f85\u3059\u308bSQL<\/h2>\n<p><code>ROLLUP<\/code>\u304c\u968e\u5c64\u7684\u306a\u96c6\u8a08\u3092\u5f97\u610f\u3068\u3059\u308b\u4e00\u65b9\u3001<code>CUBE<\/code>\u306f<strong>\u6307\u5b9a\u3055\u308c\u305f\u5217\u306e\u8003\u3048\u3089\u308c\u308b\u3059\u3079\u3066\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u7db2\u7f85\u7684\u306b\u96c6\u8a08<\/strong>\u3057\u307e\u3059\u3002\u968e\u5c64\u95a2\u4fc2\u3092\u610f\u8b58\u305b\u305a\u3001\u30b5\u30a4\u30b3\u30ed\uff08\u30ad\u30e5\u30fc\u30d6\uff09\u3092\u3042\u3089\u3086\u308b\u89d2\u5ea6\u304b\u3089\u773a\u3081\u308b\u3088\u3046\u306b\u3001\u591a\u89d2\u7684\u306a\u30af\u30ed\u30b9\u96c6\u8a08\u3092\u884c\u3044\u305f\u3044\u5834\u5408\u306b\u6700\u9069\u3067\u3059\u3002<\/p>\n<h3><code>ROLLUP<\/code>\u3068\u306e\u9055\u3044<\/h3>\n<p><code>CUBE<\/code>\u3068<code>ROLLUP<\/code>\u306e\u6700\u3082\u5927\u304d\u306a\u9055\u3044\u306f\u3001\u96c6\u8a08\u30d1\u30bf\u30fc\u30f3\u306e\u751f\u6210\u65b9\u6cd5\u306b\u3042\u308a\u307e\u3059\u3002<br \/><code>CUBE(department, position)<\/code>\u3068\u6307\u5b9a\u3057\u305f\u5834\u5408\u3001\u5185\u90e8\u7684\u306b\u306f\u4ee5\u4e0b\u306e<strong>4\u3064\u306e\u5168\u7d44\u307f\u5408\u308f\u305b<\/strong>\u3092\u751f\u6210\u3059\u308b<code>GROUPING SETS<\/code>\u3068\u7b49\u4fa1\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ol>\n<li><code>(department, position)<\/code>\uff1a\u90e8\u7f72\u3068\u5f79\u8077\u3054\u3068\u306e\u96c6\u8a08<\/li>\n<li><code>(department)<\/code>\uff1a\u90e8\u7f72\u3054\u3068\u306e\u5c0f\u8a08<\/li>\n<li><code>(position)<\/code>\uff1a\u5f79\u8077\u3054\u3068\u306e\u5c0f\u8a08  <strong>\u2190 ROLLUP\u306b\u306f\u7121\u304b\u3063\u305f\u30d1\u30bf\u30fc\u30f3<\/strong><\/li>\n<li><code>()<\/code>\uff1a\u5168\u4f53\u306e\u5408\u8a08<\/li>\n<\/ol>\n<p><code>ROLLUP<\/code>\u304c\u6307\u5b9a\u3057\u305f\u9806\u5e8f\u306b\u6cbf\u3063\u3066\u968e\u5c64\u7684\u306b\u96c6\u8a08\u3059\u308b\u306e\u306b\u5bfe\u3057\u3001<code>CUBE<\/code>\u306f\u9806\u5e8f\u3092\u8003\u616e\u305b\u305a\u3001\u3042\u3089\u3086\u308b\u30d1\u30bf\u30fc\u30f3\u306e\u96c6\u8a08\u7d50\u679c\u3092\u51fa\u529b\u3057\u307e\u3059\u3002<\/p>\n<h3>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3068SQL\u69cb\u6587<\/h3>\n<p><strong>\u3010CUBE \u3092\u4f7f\u3063\u305fSQL\u4f8b\u3011<\/strong><\/p>\n<pre><code>\nSELECT\n  department,\n  position,\n  SUM(salary) AS total_salary\nFROM\n  employees\nGROUP BY\n  CUBE (department, position);\n<\/code><\/pre>\n<h3>\u5b9f\u884c\u7d50\u679c\u3068\u8003\u5bdf<\/h3>\n<p>\u4e0a\u8a18\u306eSQL\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<code>ROLLUP<\/code>\u306e\u7d50\u679c\u306b\u52a0\u3048\u3066\u3001<code>department<\/code>\u304c<code>NULL<\/code>\u306e\u300c\u5f79\u8077\u3054\u3068\u300d\u306e\u96c6\u8a08\u884c\u304c\u8ffd\u52a0\u3055\u308c\u3066\u3044\u308b\u70b9\u306b\u6ce8\u76ee\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<table border=\"1\" style=\"width:100%; border-collapse: collapse;\">\n<thead>\n<tr>\n<th style=\"padding: 8px; text-align: left;\">department<\/th>\n<th style=\"padding: 8px; text-align: left;\">position<\/th>\n<th style=\"padding: 8px; text-align: left;\">total_salary<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 8px;\">\u55b6\u696d\u90e8<\/td>\n<td style=\"padding: 8px;\">\u90e8\u9577<\/td>\n<td style=\"padding: 8px;\">800<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u55b6\u696d\u90e8<\/td>\n<td style=\"padding: 8px;\">\u8ab2\u9577<\/td>\n<td style=\"padding: 8px;\">600<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u55b6\u696d\u90e8<\/td>\n<td style=\"padding: 8px;\">\u4e00\u822c<\/td>\n<td style=\"padding: 8px;\">800<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u55b6\u696d\u90e8<\/td>\n<td style=\"padding: 8px;\">NULL<\/td>\n<td style=\"padding: 8px;\">2200<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u958b\u767a\u90e8<\/td>\n<td style=\"padding: 8px;\">\u90e8\u9577<\/td>\n<td style=\"padding: 8px;\">850<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u958b\u767a\u90e8<\/td>\n<td style=\"padding: 8px;\">\u8ab2\u9577<\/td>\n<td style=\"padding: 8px;\">650<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u958b\u767a\u90e8<\/td>\n<td style=\"padding: 8px;\">\u4e00\u822c<\/td>\n<td style=\"padding: 8px;\">450<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u958b\u767a\u90e8<\/td>\n<td style=\"padding: 8px;\">NULL<\/td>\n<td style=\"padding: 8px;\">1950<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u4eba\u4e8b\u90e8<\/td>\n<td style=\"padding: 8px;\">\u8ab2\u9577<\/td>\n<td style=\"padding: 8px;\">580<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u4eba\u4e8b\u90e8<\/td>\n<td style=\"padding: 8px;\">\u4e00\u822c<\/td>\n<td style=\"padding: 8px;\">380<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">\u4eba\u4e8b\u90e8<\/td>\n<td style=\"padding: 8px;\">NULL<\/td>\n<td style=\"padding: 8px;\">960<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong>NULL<\/strong><\/td>\n<td style=\"padding: 8px;\"><strong>\u90e8\u9577<\/strong><\/td>\n<td style=\"padding: 8px;\"><strong>1650<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong>NULL<\/strong><\/td>\n<td style=\"padding: 8px;\"><strong>\u8ab2\u9577<\/strong><\/td>\n<td style=\"padding: 8px;\"><strong>1830<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong>NULL<\/strong><\/td>\n<td style=\"padding: 8px;\"><strong>\u4e00\u822c<\/strong><\/td>\n<td style=\"padding: 8px;\"><strong>1630<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\">NULL<\/td>\n<td style=\"padding: 8px;\">NULL<\/td>\n<td style=\"padding: 8px;\">5110<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3053\u306e\u3088\u3046\u306b<code>CUBE<\/code>\u3092\u4f7f\u3048\u3070\u3001\u300c\u90e8\u7f72\u3054\u3068\u306e\u7279\u5fb4\u300d\u3068\u300c\u5f79\u8077\u3054\u3068\u306e\u7279\u5fb4\u300d\u3068\u3044\u3046\u7570\u306a\u308b\u8ef8\u306e\u5206\u6790\u3092\u4e00\u5ea6\u306e\u30af\u30a8\u30ea\u3067\u5b9f\u884c\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u96c6\u8a08\u5bfe\u8c61\u306e\u5217\u304c\u5897\u3048\u308b\u3068\u7d44\u307f\u5408\u308f\u305b\u306e\u6570\u304c\u7206\u767a\u7684\u306b\u5897\u52a0\uff08$2^n$\u901a\u308a\uff09\u3059\u308b\u305f\u3081\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3078\u306e\u5f71\u97ff\u3092\u8003\u616e\u3057\u3066\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2>3\u3064\u306e\u9055\u3044\u3092\u6bd4\u8f03\u2502GROUPING SETS\u30fbROLLUP\u30fbCUBE\u306e\u4f7f\u3044\u5206\u3051<\/h2>\n<p>\u3053\u3053\u307e\u3067\u89e3\u8aac\u3057\u3066\u304d\u305f3\u3064\u306e\u6a5f\u80fd\u3092\u3001\u6539\u3081\u3066\u6bd4\u8f03\u3057\u3066\u6574\u7406\u3057\u307e\u3057\u3087\u3046\u3002\u305d\u308c\u305e\u308c\u306e\u7279\u5fb4\u3092\u7406\u89e3\u3057\u3001\u76ee\u7684\u306e\u96c6\u8a08\u306b\u6700\u3082\u9069\u3057\u305f\u3082\u306e\u3092\u9078\u629e\u3059\u308b\u3053\u3068\u304c\u3001\u52b9\u7387\u7684\u306a\u30c7\u30fc\u30bf\u5206\u6790\u306e\u9375\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>\u6a5f\u80fd\u6bd4\u8f03\u4e00\u89a7\u8868<\/h3>\n<table border=\"1\" style=\"width:100%; border-collapse: collapse;\">\n<thead>\n<tr>\n<th style=\"padding: 8px; text-align: left;\">\u6a5f\u80fd<\/th>\n<th style=\"padding: 8px; text-align: left;\">\u7279\u5fb4<\/th>\n<th style=\"padding: 8px; text-align: left;\">\u30a4\u30e1\u30fc\u30b8<\/th>\n<th style=\"padding: 8px; text-align: left;\">\u3053\u3093\u306a\u3068\u304d\u306b\u304a\u3059\u3059\u3081<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 8px;\"><strong><code>GROUPING SETS<\/code><\/strong><\/td>\n<td style=\"padding: 8px;\">\u5fc5\u8981\u306a\u96c6\u8a08\u30d1\u30bf\u30fc\u30f3\u3092 <strong>\u81ea\u7531\u306b\u3001\u660e\u793a\u7684\u306b<\/strong> \u6307\u5b9a\u3059\u308b\u3002<\/td>\n<td style=\"padding: 8px;\">\u30a2\u30e9\u30ab\u30eb\u30c8\uff08\u5358\u54c1\u6ce8\u6587\uff09<\/td>\n<td style=\"padding: 8px;\">\u30fb\u6c7a\u307e\u3063\u305f\u30d1\u30bf\u30fc\u30f3\u306e\u30ec\u30dd\u30fc\u30c8\u4f5c\u6210<br \/>\u30fb\u968e\u5c64\u3084\u7db2\u7f85\u6027\u304c\u5fc5\u8981\u306a\u3044\u7279\u5b9a\u306e\u96c6\u8a08<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong><code>ROLLUP<\/code><\/strong><\/td>\n<td style=\"padding: 8px;\">\u6307\u5b9a\u3057\u305f\u5217\u306e <strong>\u968e\u5c64\u306b\u5f93\u3063\u3066<\/strong> \u5c0f\u8a08\u30fb\u5408\u8a08\u3092\u81ea\u52d5\u751f\u6210\u3059\u308b\u3002<\/td>\n<td style=\"padding: 8px;\">\u30b3\u30fc\u30b9\u6599\u7406<\/td>\n<td style=\"padding: 8px;\">\u30fb\u65e5\u6b21\u2192\u6708\u6b21\u2192\u5e74\u6b21\u30ec\u30dd\u30fc\u30c8<br \/>\u30fb\u56fd\u2192\u90fd\u9053\u5e9c\u770c\u2192\u5e02\u533a\u753a\u6751\u306e\u58f2\u4e0a\u96c6\u8a08<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 8px;\"><strong><code>CUBE<\/code><\/strong><\/td>\n<td style=\"padding: 8px;\">\u6307\u5b9a\u3057\u305f\u5217\u306e <strong>\u3059\u3079\u3066\u306e\u7d44\u307f\u5408\u308f\u305b<\/strong> \u3092\u7db2\u7f85\u7684\u306b\u96c6\u8a08\u3059\u308b\u3002<\/td>\n<td style=\"padding: 8px;\">\u30d3\u30e5\u30c3\u30d5\u30a7\uff08\u5168\u7a2e\u985e\uff09<\/td>\n<td style=\"padding: 8px;\">\u30fb\u591a\u89d2\u7684\u306a\u30af\u30ed\u30b9\u96c6\u8a08<br \/>\u30fb\u30c7\u30fc\u30bf\u63a2\u7d22\u3084\u5206\u6790\u306e\u521d\u671f\u6bb5\u968e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><code>GROUPING<\/code>\u95a2\u6570\u3067\u96c6\u8a08\u884c\u3092\u5206\u304b\u308a\u3084\u3059\u304f<\/h3>\n<p><code>GROUPING SETS<\/code>\u3001<code>ROLLUP<\/code>\u3001<code>CUBE<\/code>\u3092\u4f7f\u3046\u3068\u3001\u96c6\u8a08\u884c\u306b\u306f<code>NULL<\/code>\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u5143\u306e\u30c7\u30fc\u30bf\u304c<code>NULL<\/code>\u3060\u3063\u305f\u5834\u5408\u3068\u533a\u5225\u304c\u3064\u304d\u307e\u305b\u3093\u3002\u305d\u3053\u3067\u5f79\u7acb\u3064\u306e\u304c<code>GROUPING<\/code>\u95a2\u6570\u3067\u3059\u3002<\/p>\n<p><code>GROUPING(\u5217\u540d)<\/code>\u306f\u3001\u305d\u306e\u884c\u304c\u6307\u5b9a\u3057\u305f\u5217\u3067\u96c6\u8a08\u3055\u308c\u305f\u7d50\u679c\uff08<code>NULL<\/code>\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u884c\uff09\u3067\u3042\u308c\u3070<code>1<\/code>\u3092\u3001\u305d\u3046\u3067\u306a\u3051\u308c\u3070<code>0<\/code>\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<p><strong>\u3010<code>GROUPING<\/code>\u95a2\u6570\u3092\u4f7f\u3063\u305fSQL\u4f8b\u3011<\/strong><\/p>\n<pre><code>\nSELECT\n  GROUPING(department) AS is_dept_total,\n  GROUPING(position) AS is_pos_total,\n  department,\n  position,\n  SUM(salary) AS total_salary\nFROM\n  employees\nGROUP BY\n  CUBE (department, position)\nORDER BY\n  department, position;\n<\/code><\/pre>\n<p>\u3053\u306e\u30af\u30a8\u30ea\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u3069\u306e\u5217\u304c\u96c6\u8a08\u5bfe\u8c61\u306b\u306a\u3063\u3066\u3044\u308b\u304b\u304c<code>0<\/code>\u3068<code>1<\/code>\u3067\u660e\u78ba\u306b\u5224\u5225\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306e\u51e6\u7406\u3084\u5206\u6790\u304c\u3088\u308a\u5bb9\u6613\u306b\u306a\u308a\u307e\u3059\u3002\u4f8b\u3048\u3070<code>is_dept_total<\/code>\u304c<code>1<\/code>\u306e\u884c\u306f\u3001\u90e8\u7f72\u306e\u57a3\u6839\u3092\u8d8a\u3048\u305f\u96c6\u8a08\uff08\u5f79\u8077\u3054\u3068\u306e\u96c6\u8a08\u3084\u7dcf\u8a08\uff09\u3067\u3042\u308b\u3053\u3068\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL\u3067\u30c7\u30fc\u30bf\u3092\u96c6\u8a08\u3059\u308b\u969b\u3001GROUP BY\u53e5\u306f\u975e\u5e38\u306b\u5f37\u529b\u306a\u6b66\u5668\u3067\u3059\u3002\u3057\u304b\u3057\u3001\u300c\u90e8\u7f72\u3054\u3068\u306e\u58f2\u4e0a\u300d\u300c\u5f79\u8077\u3054\u3068\u306e\u58f2\u4e0a\u300d\u300c\u5168\u793e\u306e\u7dcf\u58f2\u4e0a\u300d\u3068\u3044\u3063\u305f\u8907\u6570\u306e\u96c6\u8a08\u3092\u4e00\u5ea6\u306b\u884c\u3044\u305f\u3044\u5834\u5408\u3001\u3069\u3046\u3057\u3066\u3044\u307e\u3059\u304b\uff1f \u304a\u305d\u3089\u304f\u3001 &#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","columnck":"","stmeta_robots":"index, follow","st_titlewords":"","st_title_extra":"","st_keywords":"","st_description":"","st_display_ad_mark":"","st_display_ad_mark_hide":"","textcopyck":"","st_copyright":"","st_copyurl":"","eyecatch_set":"","st_youtube_url":"","st_youtube_eyecatch":"","headerwidget_set":"","updatewidget_set":"","kanrenwidget_set":"","ikkatuwidget_set":"","koukoku_set":"","auto_adsense_koukoku_set":"","st_redirect":"","st_redirect_url_as_canonical":"","st_redirect_pvm_do_not_track":"","post_data_updatewidget_set":"","st_post_header_under_bg":"","st_twitter_tag":"","affinger_note":"","rankdisplayck":"","st_head_code":"","st_footer_code":"","st_post_header_under_code":"","_st_toc_override":false,"_st_toc_settings":[]},"categories":[3],"tags":[6],"class_list":["post-6077","post","type-post","status-publish","format-standard","hentry","category-ipa","tag-6"],"_links":{"self":[{"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/posts\/6077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/comments?post=6077"}],"version-history":[{"count":0,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/posts\/6077\/revisions"}],"wp:attachment":[{"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/media?parent=6077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/categories?post=6077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sky-peace.net\/certified\/wp-json\/wp\/v2\/tags?post=6077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}