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
-
Data Types in VB .NET The Data types available in VB .NET, their size, type, description are summarized in the table below. Data Type Size i...
-
Methods A Method is a procedure built into the class. They are a series of statements that are executed when called. Methods allow us to han...
-
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...
-
Constructors A constructor is a special member function whose task is to initialize the objects of it's class. This is the first method ...
-
So far we’ve learnt how to select data from a database table and how to insert and update data into a database table. Now it’s time to learn...
-
Introduction: In this exercise, you will exercise the concept of pass by reference. Please not that primitive type parameters are passed ...
-
Using SQL Parameters In VB.NET, we have Windows controls that may provide parameters for filtering data from the database. A common scenario...
-
The SQL UPDATE general syntax looks like this: UPDATE Table1 SET Column1 = Value1, Column2 = Value2 WHERE Some_Column = Some_Value The SQL U...
-
Interfaces Interfaces allow us to create definitions for component interaction. They also provide another way of implementing polymorphism. ...
-
The SQL INSERT INTO syntax has 2 main forms and the result of either of them is adding a new row into the database table. The first syntax f...
No comments:
Post a Comment