Home >> SQL Aggregate Functions
SQL has a lot of built-in functions for counting and calculations.
SELECT function(column) FROM table
There are several basic types and categories of functions in SQL. The basic types of functions are:
Aggregate functions operate against a collection of values, but return a single value.
Note: If used among many other expressions in the item list of a SELECT statement, the SELECT must have a GROUP BY clause!!
The table below lists some of the more useful Aggregate Functions (not an exhaustive list)
| Function | Description |
|---|---|
| AVG(column) | Returns the average value of a column |
| COUNT(column) | Returns the number of rows (without a NULL value) of a column |
| COUNT(*) | Returns the number of selected rows |
| COUNT(DISTINCT column) | Returns the number of distinct results |
| MAX(column) | Returns the highest value of a column |
| MIN(column) | Returns the lowest value of a column |
| SUM(column) | Returns the sum of a column |
Scalar functions operate against a single value and return a single value based on the input value.
There are many different types of Scalar Function in SQL Server 2000. It' even possible to define your own functions using T-SQL. The following categories contain the most useful functions:
For example, the function UPPER (a string function), returns a character expression with lowercase character data converted to uppercase.
SELECT UPPER(first_name) FROM sales_contacts
A comprehensive list of SQL Server Functions can be found here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_fafz_ 9dyr.asp
Partners: Hearing Aid Talk Forum for Hearing Aids | One Direction Forum | Adult Toys
© Pixel Kicks, 5 Marlborough Road, Royton, Oldham, OL2 6AU.