Tuesday, February 12, 2013

SQL: Summarizing and Grouping Data

Print Friendly and PDF


http://www.flickr.com/photos/konnecke/922432859/

Data Summarization

SQL has aggregate functions that allow you to summarize large volumes of data. Summarizing data helps to determine trends. Many times data needs to be summarized with reports. Aggregate functions
take the values of multiple rows grouped together, i.e., values stored in a column, and returns a single value. 

Common aggregate Microsoft SQL functions:


AVG(): Returns the average of data stored in a column

COUNT(*):  Counts the rows in a table (including NULL values)

COUNT (Column name):  Counts the rows in a column (excluding Null values)

FIRST():  Returns the first value stored in a column

LAST():  Returns the last value stored in a column

MAX():  Returns the highest value stored in a column

MIN():  Returns the lowest value stored in a column

SUM():  Returns the sum of values stored in a column