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
Popular Posts
-
ADO .NET Most applications need data access at one point of time making it a crucial component when working with applications. Data access i...
-
The SQL AVG aggregate function selects the average value for certain table column. Have a look at the SQL AVG syntax: SELECT AVG(Column1) FR...
-
The SQL IN clause allows you to specify discrete values in your SQL WHERE search criteria. THE SQL IN syntax looks like this: SELECT Column1...
-
2.2 Automatic Memory Management The Common Language Runtime does more for your C# and .NET managed executable than just JIT compile ...
-
ARRAYS: An array is a group of related data items that share a common name.For instance,we can define an array name salary to represent a se...
-
Data Adapter Configuration Wizard Generating DataSet To create a DataSet, select Data->Generate DataSet from the main menu. From the dial...
-
Creating DataTable Visual Basic allows us to create our own Tables and work with them. The DataTable is an in-memory representation of a blo...
-
As mentioned on the .NET Framework page, .NET Framework is designed for cross-language compatibility. Cross-language compatibility means .NE...
-
The SQL SELECT statement is used to select data from a SQL database table. This is usually the very first SQL command every SQL newbie learn...
-
In the previous chapter, you learned how to connect to SQL Server Database Server . In this chapter, you can find more about how to use Mana...
No comments:
Post a Comment