What are the commands available for Summarizing Data in SQL Server?
We have CUBE or ROLLUP operators to generate summary reports. Both are part of the GROUP BY clause of the SELECT statement. We have COMPUTE or COMPUTE BY operators that are used with the GROUP BY clause.
CUBE Operator The CUBE operator generates a result set in the form of multi-dimensional cube.
ROLLUP Operator The ROLLUP operator generating reports that contain subtotals and totals.
What are the commands available for Summarizing Data in SQL Server?
Commands for summarizing data in SQL Server:Command | Description | Syntax/Example |
SUM | Sums related values | SELECT SUM(Sal) as Tot from Table1; |
AVG | Average value | SELECT AVG(Sal) as Avg_Sal from Table1; |
COUNT | Returns number of rows of resultset | SELECT COUNT(*) from Table1; |
MAX | Returns max value from a resultset | SELECT MAX(Sal) from Table1; |
MIN | Returns min value from a resultset | SELECT MIN(Sal) from Table1; |
GROUP BY | Arrange resultset in groups | SELECT ZIP,City FROM Emp GROUP BY ZIP |
ORDER BY | Sort resultset | SELECT ZIP,City FROM Emp ORDER BY City |