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
-
Now I will show you how to retrieve the data posted from a HTML file in a JSP page. Consider an html page that prompts the user to enter his...
-
4.1 Object Oriented Code Reuse Code reuse has been a goal for computer scientist for decades now. Part of the promise of object ori...
-
4.2 The Framework Class Library Now that you have a taste of the goals and groundwork laid by the CLR and managed code, let’s taste ...
-
Data Access with Server Explorer Visual Basic allows us to work with databases in two ways, visually and code. In Visual Basic, Server Explo...
-
The SQL MAX aggregate function allows us to select the highest (maximum) value for a certain column. The SQL MAX function syntax is very sim...
-
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...
-
The SQL DISTINCT clause is used together with the SQL SELECT keyword, to return a dataset with unique entries for certain database table col...
-
Statements and Scope Statements A statement is a complete instruction. It can contain keywords, operators, variables, literals, expressions ...
-
# When the user submits form, his information is sent to the corresponding servlet file because we've set the ACTION attribute to point ...
No comments:
Post a Comment