{"id":8534,"date":"2019-01-26T12:00:06","date_gmt":"2019-01-26T12:00:06","guid":{"rendered":"https:\/\/dbtut.com\/?p=8534"},"modified":"2019-01-26T12:31:51","modified_gmt":"2019-01-26T12:31:51","slug":"grouping-sets-operator-in-sql-servertsql","status":"publish","type":"post","link":"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/","title":{"rendered":"GROUPING SETS Operator in SQL SERVER(TSQL)"},"content":{"rendered":"<p id=\"MNoDgEw\">\n<p>SQL Server supports grouping of data with GROUP BY since older versions, and also offers WITH ROLLUP and WITH CUBE operators for grand-total and sub-totals. SQL Server 2008 provides a new operator named GROUPING SETS.\u00a0With SQL Server 2008, it is recommended to use GROUPING SETS instead of WITH ROLLUP or WITH CUBE operators.<\/p>\n<p>You can find many detailed examples about GROUPING SETS, ROLLUP and CUBE operators in this article.<\/p>\n<p>And alson you can find the details of GROUP BY, WITH ROLLUP and WITH CUBE in the below articles.<\/p>\n<p>&#8220;<a href=\"https:\/\/dbtut.com\/index.php\/2019\/01\/06\/group-by-clause-sum-max-min-avg-count-and-count_big-functions-in-sql-server-tsql\/\" target=\"_blank\" rel=\"noopener\">Group By Clause, SUM, MAX, MIN, AVG, COUNT and COUNT_BIG Functions in SQL Server<\/a>&#8220;,<\/p>\n<p>&#8220;<a href=\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/with-rollup-and-with-cube-operators-in-sql-servertsql\/\" target=\"_blank\" rel=\"noopener\">WITH ROLLUP and WITH CUBE Operators in SQL Server(TSQL)<\/a>&#8221;<\/p>\n<p>Also you should read the below article too.<\/p>\n<p>&#8220;<a href=\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-and-grouping_id-functions-in-sql-servertsql\/\" target=\"_blank\" rel=\"noopener\">GROUPING and GROUPING_ID Functions in SQL Server(TSQL)<\/a>&#8221;<\/p>\n<p>Let&#8217;s make examples for a better understanding of GROUPING SETS Operator.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>First, we create a table with the help of the following script and add a few records into this table.<\/p>\n<pre class=\"lang:default decode:true \">CREATE TABLE [dbo].[Sales](\n[ID] [int] NULL,\n[Location] [varchar](50) NULL,\n[Month] [varchar](50) NULL,\n[Category] [varchar](50) NULL,\n[Price] [int] NULL\n) ON [PRIMARY]\nGO\nINSERT INTO [dbo].[Sales] VALUES (1,'L1','A2','K1',100),\n(2,'L2','A2','K1',85),\n(3,'L1','A2','K1',150),\n(4,'L1','A1','K1',90),\n(5,'L1','A1','K2',80),\n(6,'L2','A1','K2',90),\n(7,'L2','A1','K1',80)\nGO\nSelect * FROM [dbo].[Sales]<\/pre>\n<p id=\"QVnQUIL\"><img loading=\"lazy\" decoding=\"async\" width=\"670\" height=\"592\" class=\"size-full wp-image-8539  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b02629480f.png\" alt=\"\" \/><\/p>\n<p>This table has 3 fields that we can use as a dimension. (Location, Month and Category).<\/p>\n<p>We will also use the Price column as KPI \/ Numeric Indicator. Our goal is to see the sum of each dimension at the same time as below.<\/p>\n<p>As can be seen from the result of below query, the sum of the Month and Location data appears in the same list. To do this in SQL, it is necessary to group each field and merge it with UNION.<\/p>\n<pre class=\"lang:default decode:true \">SELECT '' AS [Location], [Month], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY [Month]\nUNION ALL\nSELECT [Location], '' [Month], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY [Location]<\/pre>\n<p id=\"jmKcYZT\"><img loading=\"lazy\" decoding=\"async\" width=\"611\" height=\"344\" class=\"size-full wp-image-8540  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b4509bc568.png\" alt=\"\" \/><\/p>\n<p>In this way, when we want to include more than one dimension, we must create a UNION series for each. The GROUPING SETS clause that comes with SQL Server 2008 offers both flexibility and performance. This sentence, which is compatible with ANSI SQL 2006, can be considered as a function used with GROUP BY. As a parameter, it is enough to write the columns to be aggregated.<\/p>\n<pre class=\"lang:default decode:true \">SELECT [Location], [Month], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY\nGROUPING SETS\n(\n[Location],\n[Month]\n)<\/pre>\n<p id=\"DVyzRct\"><img loading=\"lazy\" decoding=\"async\" width=\"658\" height=\"667\" class=\"size-full wp-image-8541  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b47732519d.png\" alt=\"\" \/><\/p>\n<p>Or let&#8217;s replace NULL values to get exactly the same image in our example.<\/p>\n<pre class=\"lang:default decode:true \">SELECT ISNULL([Location],'') AS Location, ISNULL([Month],'') AS Month, SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY\nGROUPING SETS\n(\n[Location],\n[Month]\n)<\/pre>\n<p id=\"eLdlcmK\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-8543  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b4898bc937.png\" alt=\"\" width=\"741\" height=\"577\" \/><\/p>\n<p>Using the three dimensions in our example, let&#8217;s calculate all possibilities separately without GROUPING SETS and using GROUPING SETS.<\/p>\n<pre class=\"lang:default decode:true\">SELECT NULL AS [Location], [Month], [Category], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY [Month],[Category]\nUNION ALL\nSELECT [Location], NULL [Month], [Category], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY [Location],[Category]\nUNION ALL\nSELECT [Location], [Month], NULL [Category], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY [Location],[Month]\nOrder By [Location]<\/pre>\n<pre class=\"lang:default decode:true \">SELECT [Location], [Month], [Category], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY\nGROUPING SETS\n(\n([Month], [Category]),\n([Location], [Category]),\n([Location], [Month])\n)\nOrder By [Location]<\/pre>\n<p>When you run the above two queries, a result returns as follows.<\/p>\n<p id=\"iZgBlyS\">\n<p id=\"blAaxyA\"><img loading=\"lazy\" decoding=\"async\" width=\"591\" height=\"534\" class=\"size-full wp-image-8545  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b4cd2658fb.png\" alt=\"\" \/><\/p>\n<p>Let&#8217;s calculate the sub-total and grand-total by using the Location and Month dimensions.<\/p>\n<pre class=\"lang:default decode:true \">SELECT [Location], [Month], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY [Location], [Month]\nUNION\nSELECT [Location], NULL, SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY [Location]\nUNION\nSELECT NULL, NULL, SUM(Price) Endorsement\nFROM [dbo].[Sales]<\/pre>\n<p id=\"tKVKYsh\"><img loading=\"lazy\" decoding=\"async\" width=\"641\" height=\"458\" class=\"size-full wp-image-8546  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b89d158de5.png\" alt=\"\" \/><\/p>\n<p>To make it clearer, let&#8217;s sort:<\/p>\n<pre class=\"lang:default decode:true \">SELECT * FROM (\nSELECT [Location], [Month], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY [Location], [Month]\nUNION\nSELECT [Location], NULL, SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY [Location]\nUNION\nSELECT NULL, NULL, SUM(Price) Endorsement\nFROM [dbo].[Sales]\n) as T ORDER BY ISNULL([Location],'ZZZZ'), ISNULL([Month],'ZZZZ')<\/pre>\n<p id=\"hHEydZF\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"501\" class=\"size-full wp-image-8547  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b8a5c19ad3.png\" alt=\"\" \/><\/p>\n<p>Instead of combining this type of process with UNION for each dimension, we do this with WITH ROLLUP or WITH CUBE. So we&#8217;ll get the same result with an easier typing.<\/p>\n<pre class=\"lang:default decode:true \">SELECT [Location], [Month], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY [Location], [Month]\nWITH ROLLUP<\/pre>\n<p id=\"cGcNYMY\"><img loading=\"lazy\" decoding=\"async\" width=\"656\" height=\"584\" class=\"size-full wp-image-8548  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b8b42935c4.png\" alt=\"\" \/><\/p>\n<p>To get the same result as GROUPING SETS, we need to write the fields to be aggregated.<\/p>\n<pre class=\"lang:default decode:true\">SELECT [Location], [Month], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY\nGROUPING SETS\n(\n([Location], [Month]),\n[Location],\n()\n)<\/pre>\n<p id=\"EfNeEUV\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"546\" class=\"size-full wp-image-8549  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b8d63d7ee4.png\" alt=\"\" \/><\/p>\n<p>As you can see, there is flexibility in the GROUPING SETS method. WITH ROLLUP automatically creates a grand total for all fields grouped, while GROUPING SETS creates only for what we do. For example, if you do not want to calculate the grand total, simply remove the line &#8220;()&#8221; in GROUPING SETS.<\/p>\n<p><strong>GROUPING SETS without Grand Total:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">SELECT [Location], [Month], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY\nGROUPING SETS\n(\n([Location], [Month]),\n[Location]\n)<\/pre>\n<p id=\"gywOEQe\"><img loading=\"lazy\" decoding=\"async\" width=\"615\" height=\"417\" class=\"size-full wp-image-8550  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b8ed9410eb.png\" alt=\"\" \/><\/p>\n<p><strong>GROUPING SETS without Sub Total and Grand Total:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">SELECT [Location], [Month], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY\nGROUPING SETS\n(\n([Location], [Month])\n)<\/pre>\n<p id=\"Bqniefm\"><img loading=\"lazy\" decoding=\"async\" width=\"677\" height=\"371\" class=\"size-full wp-image-8551  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b8f09da0ef.png\" alt=\"\" \/><\/p>\n<p><strong>GROUPING SETS with only Grand Total:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">SELECT [Location], [Month], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY\nGROUPING SETS\n(\n([Location], [Month]),\n()\n)<\/pre>\n<p id=\"SYQEeIV\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"406\" class=\"size-full wp-image-8552  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b8f61ae5b0.png\" alt=\"\" \/><\/p>\n<p>Let&#8217;s add the &#8220;Month&#8221; field to GROUPING SETS. Thus, all possible aggregated rows will be created for Location and Month fields. We were doing this with WITH CUBE.<\/p>\n<p><strong>WITH CUBE Method:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">SELECT [Location], [Month], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY [Location], [Month]\nWITH CUBE<\/pre>\n<p id=\"MORlMgH\"><img loading=\"lazy\" decoding=\"async\" width=\"617\" height=\"415\" class=\"size-full wp-image-8553  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b90d56e7e8.png\" alt=\"\" \/><\/p>\n<p><strong>WITH GROUPING SETS Method:<\/strong><\/p>\n<p>The order of use of the dimensions in GROUPING SETS is not important. It always returns the same result.<\/p>\n<pre class=\"lang:default decode:true \">SELECT [Location], [Month], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY\nGROUPING SETS\n(\n([Location], [Month]),\n[Location],\n[Month],\n()\n)<\/pre>\n<p id=\"SVZMMPr\"><img loading=\"lazy\" decoding=\"async\" width=\"741\" height=\"503\" class=\"size-full wp-image-8554  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b90f9ae27f.png\" alt=\"\" \/><\/p>\n<p>Let&#8217;s add 3 fields in our example without grand-total.<\/p>\n<pre class=\"lang:default decode:true \">SELECT [Location], [Month], [Category], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY\nGROUPING SETS\n(\n([Location], [Month], [Category]),\n([Location], [Month]),\n[Location],\n[Month]\n)<\/pre>\n<p id=\"hfTeViM\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"584\" class=\"size-full wp-image-8555  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b922e5350f.png\" alt=\"\" \/><\/p>\n<p>One of the advantages offered by GROUPING SETS is that sub-totals can only be created for certain columns. In our previous example, a sub-total row was created for all groups. However, we can create a sub-total for the Month and Category by fixing the location.<\/p>\n<pre class=\"lang:default decode:true \">SELECT [Location], [Month], [Category], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY\nGROUPING SETS\n(\n[Location], ROLLUP([Month], [Category])\n)<\/pre>\n<p id=\"VbIofaz\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"446\" class=\"size-full wp-image-8556  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b931fdb601.png\" alt=\"\" \/><\/p>\n<p><strong>Another Example:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">SELECT [Location], [Month], [Category], SUM(Price) Endorsement\nFROM [dbo].[Sales]\nGROUP BY\nGROUPING SETS\n(\n[Location], [Category], ROLLUP([Month])\n)<\/pre>\n<p id=\"NxaEPcn\"><img loading=\"lazy\" decoding=\"async\" width=\"688\" height=\"388\" class=\"size-full wp-image-8557  aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b94129b0dd.png\" alt=\"\" \/><\/p>\n<p><strong>CONCLUSION:<\/strong><\/p>\n<p>With SQL Server 2008, it is recommended to use GROUPING SETS instead of WITH ROLLUP or WITH CUBE operators.<\/p>\n\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_8534\" class=\"pvc_stats all  \" data-element-id=\"8534\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/dbtut.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>SQL Server supports grouping of data with GROUP BY since older versions, and also offers WITH ROLLUP and WITH CUBE operators for grand-total and sub-totals. SQL Server 2008 provides a new operator named GROUPING SETS.\u00a0With SQL Server 2008, it is recommended to use GROUPING SETS instead of WITH ROLLUP or WITH CUBE operators. You can &hellip;<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_8534\" class=\"pvc_stats all  \" data-element-id=\"8534\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/dbtut.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":470,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[3,1596],"tags":[1791,1792,1788,1789,1793,1790],"class_list":["post-8534","post","type-post","status-publish","format-standard","","category-mssql","category-tsql","tag-cube-operator","tag-difference-between-grouping-sets","tag-grouping-sets-operator","tag-rollup","tag-rollup-and-cube","tag-rollup-operator"],"aioseo_notices":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>GROUPING SETS Operator in SQL SERVER(TSQL) - Database Tutorials<\/title>\n<meta name=\"description\" content=\"GROUPING SETS Operator in SQL SERVER(TSQL)\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"GROUPING SETS Operator in SQL SERVER(TSQL) - Database Tutorials\" \/>\n<meta property=\"og:description\" content=\"GROUPING SETS Operator in SQL SERVER(TSQL)\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/\" \/>\n<meta property=\"og:site_name\" content=\"Database Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-26T12:00:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-01-26T12:31:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b02629480f.png\" \/>\n<meta name=\"author\" content=\"Ahmet KAYMAZ\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ahmet KAYMAZ\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/\"},\"author\":{\"name\":\"Ahmet KAYMAZ\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/80688c36fa505cc2cb8533399f77e5ad\"},\"headline\":\"GROUPING SETS Operator in SQL SERVER(TSQL)\",\"datePublished\":\"2019-01-26T12:00:06+00:00\",\"dateModified\":\"2019-01-26T12:31:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/\"},\"wordCount\":628,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/dbtut.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b02629480f.png\",\"keywords\":[\"CUBE Operator\",\"Difference Between GROUPING SETS\",\"GROUPING SETS Operator\",\"ROLLUP\",\"ROLLUP and CUBE\",\"ROLLUP Operator\"],\"articleSection\":[\"MSSQL\",\"TSQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/\",\"url\":\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/\",\"name\":\"GROUPING SETS Operator in SQL SERVER(TSQL) - Database Tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/dbtut.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b02629480f.png\",\"datePublished\":\"2019-01-26T12:00:06+00:00\",\"dateModified\":\"2019-01-26T12:31:51+00:00\",\"description\":\"GROUPING SETS Operator in SQL SERVER(TSQL)\",\"breadcrumb\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#primaryimage\",\"url\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b02629480f.png\",\"contentUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b02629480f.png\",\"width\":670,\"height\":592},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dbtut.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"GROUPING SETS Operator in SQL SERVER(TSQL)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dbtut.com\/#website\",\"url\":\"https:\/\/dbtut.com\/\",\"name\":\"Database Tutorials\",\"description\":\"MSSQL, Oracle, PostgreSQL, MySQL, MariaDB, DB2, Sybase, Teradata, Big Data, NOSQL, MongoDB, Couchbase, Cassandra, Windows, Linux\",\"publisher\":{\"@id\":\"https:\/\/dbtut.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dbtut.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/dbtut.com\/#organization\",\"name\":\"dbtut\",\"url\":\"https:\/\/dbtut.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg\",\"contentUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg\",\"width\":223,\"height\":36,\"caption\":\"dbtut\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/80688c36fa505cc2cb8533399f77e5ad\",\"name\":\"Ahmet KAYMAZ\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ec882e49e815780808a0ba0abd1a4df1199c625ef7357c66e583dedd1b079d31?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ec882e49e815780808a0ba0abd1a4df1199c625ef7357c66e583dedd1b079d31?s=96&d=mm&r=g\",\"caption\":\"Ahmet KAYMAZ\"},\"url\":\"https:\/\/dbtut.com\/index.php\/author\/ahmetkaymaz\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"GROUPING SETS Operator in SQL SERVER(TSQL) - Database Tutorials","description":"GROUPING SETS Operator in SQL SERVER(TSQL)","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/","og_locale":"en_US","og_type":"article","og_title":"GROUPING SETS Operator in SQL SERVER(TSQL) - Database Tutorials","og_description":"GROUPING SETS Operator in SQL SERVER(TSQL)","og_url":"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/","og_site_name":"Database Tutorials","article_published_time":"2019-01-26T12:00:06+00:00","article_modified_time":"2019-01-26T12:31:51+00:00","og_image":[{"url":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b02629480f.png","type":"","width":"","height":""}],"author":"Ahmet KAYMAZ","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ahmet KAYMAZ","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#article","isPartOf":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/"},"author":{"name":"Ahmet KAYMAZ","@id":"https:\/\/dbtut.com\/#\/schema\/person\/80688c36fa505cc2cb8533399f77e5ad"},"headline":"GROUPING SETS Operator in SQL SERVER(TSQL)","datePublished":"2019-01-26T12:00:06+00:00","dateModified":"2019-01-26T12:31:51+00:00","mainEntityOfPage":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/"},"wordCount":628,"commentCount":0,"publisher":{"@id":"https:\/\/dbtut.com\/#organization"},"image":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#primaryimage"},"thumbnailUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b02629480f.png","keywords":["CUBE Operator","Difference Between GROUPING SETS","GROUPING SETS Operator","ROLLUP","ROLLUP and CUBE","ROLLUP Operator"],"articleSection":["MSSQL","TSQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/","url":"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/","name":"GROUPING SETS Operator in SQL SERVER(TSQL) - Database Tutorials","isPartOf":{"@id":"https:\/\/dbtut.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#primaryimage"},"image":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#primaryimage"},"thumbnailUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b02629480f.png","datePublished":"2019-01-26T12:00:06+00:00","dateModified":"2019-01-26T12:31:51+00:00","description":"GROUPING SETS Operator in SQL SERVER(TSQL)","breadcrumb":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#primaryimage","url":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b02629480f.png","contentUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/01\/img_5c4b02629480f.png","width":670,"height":592},{"@type":"BreadcrumbList","@id":"https:\/\/dbtut.com\/index.php\/2019\/01\/26\/grouping-sets-operator-in-sql-servertsql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dbtut.com\/"},{"@type":"ListItem","position":2,"name":"GROUPING SETS Operator in SQL SERVER(TSQL)"}]},{"@type":"WebSite","@id":"https:\/\/dbtut.com\/#website","url":"https:\/\/dbtut.com\/","name":"Database Tutorials","description":"MSSQL, Oracle, PostgreSQL, MySQL, MariaDB, DB2, Sybase, Teradata, Big Data, NOSQL, MongoDB, Couchbase, Cassandra, Windows, Linux","publisher":{"@id":"https:\/\/dbtut.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dbtut.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/dbtut.com\/#organization","name":"dbtut","url":"https:\/\/dbtut.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/#\/schema\/logo\/image\/","url":"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg","contentUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg","width":223,"height":36,"caption":"dbtut"},"image":{"@id":"https:\/\/dbtut.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/dbtut.com\/#\/schema\/person\/80688c36fa505cc2cb8533399f77e5ad","name":"Ahmet KAYMAZ","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ec882e49e815780808a0ba0abd1a4df1199c625ef7357c66e583dedd1b079d31?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ec882e49e815780808a0ba0abd1a4df1199c625ef7357c66e583dedd1b079d31?s=96&d=mm&r=g","caption":"Ahmet KAYMAZ"},"url":"https:\/\/dbtut.com\/index.php\/author\/ahmetkaymaz\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts\/8534","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/users\/470"}],"replies":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/comments?post=8534"}],"version-history":[{"count":0,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts\/8534\/revisions"}],"wp:attachment":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/media?parent=8534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/categories?post=8534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/tags?post=8534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}