Archive for the ‘ Math Functions ’ Category

SQL SUM Function

The SUM function is used to calculate the total for a column. The syntax is:

SELECT SUM(“column_name”)
FROM
“table_name”

For example, if we want to get the sum of all sales from the following table,

Store Sales Information

Store Name Sales
Atlanta $1500
Boston $250
LA $300
Dallas $700

we would type in
SELECT SUM(Sales) FROM Store_Information

Result:
SUM(Sales)
$2750

$2750 represents the sum of all Sales entries: $1500 + $250 + $300 + $700.

SQL MIN Function

SQL uses the MIN function to find the maximum value in a column.

The syntax for using the MIN function is:

SELECT MIN(“column_name”)
FROM
“table_name”

For example, if we want to get the lowest sales from the following table

Store Sales Information

Store Name Sales
Atlanta $1500
Boston $250
LA $300
Dallas $700

type in

SELECT MIN(Sales) FROM Store_Information

Result:
MIN(Sales)
$250

$250 represents the minimum value of all Sales entries: $1500, $250, $300, and $700.

SQL MAX Function

SQL uses the MAX function to find the maximum value in a column. The syntax for using the MAX function is:

SELECT MAX(“column_name”)
FROM
“table_name”

For example, if we want to get the highest sales from the following table,

Store Sales Information

Store Name Sales
Atlanta $1500
Boston $250
LA $300
Dallas $700


we would type in
SELECT MAX(Sales) FROM Store_Information

Result:
MAX(Sales)
$1500
$1500 represents the maximum value of all Sales entries: $1500, $250, $300, and $700.

SQL Count Function

Another arithmetic function is COUNT. This allows us to COUNT up the number of row in a certain table. The syntax is:

SELECT COUNT(“column_name”)
FROM “table_name”

For example, if we want to find the number of store entries in our table, type:

Store Sales Information

Store Name Sales
Atlanta $1500
Boston $250
LA $300
Dallas $700

SELECT COUNT(store_name)
FROM
Store_Information

Result:
Count(store_name)
4

Get Adobe Flash playerPlugin by wpburn.com wordpress themes