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
-
OPERATORS: There are 7 operators they are: 1.Arithmetic operators : +,-,*,/,% : addition,subtraction,multiply,division...
-
INTRODUCTION TO 'C': C is a programming language developed at AT & T's Bell laboratories of USA in 1972.it was designed by d...
-
JSP pages are high level extension of servlet and it enable the developers to embed java code in html pages. JSP files are finally compiled ...
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Using JavaServer Pages...
-
SYMBOLIC CONSTANTS OR MACRO: In this #define is a macro used for a constant value to be assigned in the program. for example: pi its value i...
-
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...
-
To simplify code in JSP expressions and scriptlets, you are supplied with eight automatically defined variables, sometimes called implicit o...
-
Learning about Events Visual Basic is "Event Driven" language. What does it mean? Everything that happening, launch an event. You...
-
<%@page contentType="text/html" import="java.util.*" %> <!-- http://www.roseindia.net/jsp --> ...
-
CONTROL STRUCTURES: Three types of control structures: 1.Decision control structure : if,if else,nested if etc 2.Loop control structure ...
No comments:
Post a Comment