Please visit our sponsors !
SQL Functions
SQL has a lot of built-in functions for counting and calculations.
Function Syntax
The syntax for built-in SQL functions is:
SELECT function(column) FROM table |
Original Table (used in the examples)
Name |
Age |
Hansen, Ola |
34 |
Svendson, Tove |
45 |
Pettersen, Kari |
19 |
Function AVG(column)
The AVG function returns the average value of a column in a selection. NULL values are not included in the
calculation.
Example
This example returns the average age of the persons in the "Persons"
table:
SELECT AVG(Age) FROM Persons |
Result
Example
This example returns the average age for persons that are older than 20
years:
SELECT AVG(Age) FROM Persons WHERE Age>20 |
Result
Function MAX(column)
The MAX function returns the highest value in a column. NULL values are not included in the
calculation.
Example
SELECT MAX(Age) FROM Persons |
Result:
Function MIN(column)
The MIN function returns the lowest value in a column. NULL values are not included in the
calculation.
Example
SELECT MIN(Age) FROM Persons |
Result:
Note: The MIN and MAX functions can also be used on text columns, to find the
highest or lowest value in alphabetical order.
Function SUM(column)
The SUM function returns the total sum of a column in a given selection. NULL values are not included in the
calculation.
Example
This example returns the sum of all ages in the "person" table:
SELECT SUM(Age) FROM Persons |
Result:
ExampleThis example returns the sum of ages for persons that are more
than 20 years old:
SELECT SUM(Age) FROM Persons WHERE Age>20 |
Result:
Jump to: Top of Page
or HOME or
Printer friendly page
Search W3Schools:
What Others Say About Us
Does the world know about us? Check out these places:
Dogpile
Alta Vista
MSN
Google
Excite
Lycos
Yahoo
Ask Jeeves
We Help You For Free. You Can Help Us!
W3Schools is for training only. We do not warrant its correctness or its fitness for use.
The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our
terms of use and
privacy policy.
Copyright 1999-2002 by Refsnes Data. All Rights Reserved
|