rollup

How to automatically insert a blank row after a group of data

送分小仙女□ 提交于 2019-11-26 22:31:09
I have created a sample table below that is similar-enough to my table in excel that it should serve to illustrate the question. I want to simply add a row after each distinct datum in column1 (simplest way, using excel, thanks). _ CURRENT TABLE: column1 | column2 | column3 ---------------------------------- A | small | blue A | small | orange A | small | yellow B | med | yellow B | med | blue C | large | green D | large | green D | small | pink _ DESIRED TABLE Note: the blank row after each distinct column1 column1 | column2 | column3 ---------------------------------- A | small | blue A |

Add a summary row with totals

大兔子大兔子 提交于 2019-11-26 20:13:47
I know this sounds crazy and probably should not be done this way but I need something like this - I have a records from SELECT [Type], [Total Sales] From Before I want to add an extra row at the end to show the SUM at the end of the table (After). Could this be done? If you are on SQL Server 2008 or later version, you can use the ROLLUP() GROUP BY function: SELECT Type = ISNULL(Type, 'Total'), TotalSales = SUM(TotalSales) FROM atable GROUP BY ROLLUP(Type) ; This assumes that the Type column cannot have NULLs and so the NULL in this query would indicate the rollup row, the one with the grand

How to automatically insert a blank row after a group of data

☆樱花仙子☆ 提交于 2019-11-26 08:23:43
问题 I have created a sample table below that is similar-enough to my table in excel that it should serve to illustrate the question. I want to simply add a row after each distinct datum in column1 (simplest way, using excel, thanks). _ CURRENT TABLE: column1 | column2 | column3 ---------------------------------- A | small | blue A | small | orange A | small | yellow B | med | yellow B | med | blue C | large | green D | large | green D | small | pink _ DESIRED TABLE Note: the blank row after each

Add a summary row with totals

泄露秘密 提交于 2019-11-26 06:32:21
问题 I know this sounds crazy and probably should not be done this way but I need something like this - I have a records from SELECT [Type], [Total Sales] From Before I want to add an extra row at the end to show the SUM at the end of the table (After). Could this be done? 回答1: If you are on SQL Server 2008 or later version, you can use the ROLLUP() GROUP BY function: SELECT Type = ISNULL(Type, 'Total'), TotalSales = SUM(TotalSales) FROM atable GROUP BY ROLLUP(Type) ; This assumes that the Type