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
-
INTRODUCTION TO 'C': C is a programming language developed at AT & T's Bell laboratories of USA in 1972.it was designed by d...
-
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...
-
Learning about Parameters Parameters are variables that being passed to a Sub. Look at the first line of the Command Button's Click even...
-
The SQL JOIN clause is used whenever we have to select data from 2 or more tables. To be able to use SQL JOIN clause to extract data from 2 ...
-
CONTROL STRUCTURES: Three types of control structures: 1.Decision control structure : if,if else,nested if etc 2.Loop control structure ...
-
SQL aliases can be used with database tables and with database table columns, depending on task you are performing. SQL column aliases are u...
-
The SQL SELECT INTO statement is used to select data from a SQL database table and to insert it to a different table at the same time. The g...
-
IT professionals and students from all over the world have many options for SQL training nowadays. They can learn SQL by going to instructo...
-
The SQL GROUP BY statement is used along with the SQL aggregate functions like SUM to provide means of grouping the result dataset by certai...
-
The foundation of every Relational Database Management System is a database object called table. Every database consists of one or more tabl...
No comments:
Post a Comment