SQL Tutorial - Learn SQL




SQL Tutorial
SQL Cheat Sheet
SQL Database Table
SQL SELECT
SQL SELECT INTO
SQL DISTINCT
SQL WHERE
SQL LIKE
SQL INSERT INTO
SQL UPDATE
SQL DELETE
SQL ORDER BY
SQL OR & AND
SQL IN
SQL BETWEEN
SQL Aliases
SQL COUNT
SQL MAX
SQL MIN
SQL AVG
SQL SUM
SQL GROUP BY
SQL HAVING
SQL JOIN
SQL Training
SQL Server
SQL Hosting
SQL Replication
ETL - Extract, Transform, and Load


SQL SUM

The SQL SUM aggregate function allows selecting the total for a numeric column.

The SQL SUM syntax is displayed below:


SELECT SUM(Column1)
FROM Table1

We are going to use the Sales table to illustrate the use of SQL SUM clause:

Sales:

CustomerID Date SaleAmount
2 5/6/2004 $100.22
1 5/7/2004 $99.95
3 5/7/2004 $122.95
3 5/13/2004 $100.00
4 5/22/2004 $555.55

Consider the following SQL SUM statement:


SELECT SUM(SaleAmount)
FROM Sales

This SQL statement will return the sum of all SaleAmount fields and the result of it will be:

SaleAmount
$978.67

Of course you can specify search criteria using the SQL WHERE clause in your SQL SUM statement. If you want to select the total sales for customer with CustomerID = 3, you will use the following SQL SUM statement:


SELECT SUM(SaleAmount)
FROM Sales
WHERE CustomerID = 3

The result will be:

SaleAmount
$222.95



ASP Hosting




If you want to contact us please email to
contact @ sql-tutorial.net


Link to SQL Tutorial


Bookmark SQL Tutorial


Copyright


Disclaimer



  © Art Branch Inc. 2004