Wednesday, 30 March 2011

SQl SUM() Function

The SUM() FunctionThe SUM() function returns the total sum of a numeric column.

SQL SUM() Syntax

SELECT SUM(column_name) FROM table_name


SQL SUM() ExampleWe have the following "Orders" table:

O_Id
OrderDate
OrderPrice
Customer
12008/11/121000Hansen
22008/10/231600Nilsen
32008/09/02700Hansen
42008/09/03300Hansen
52008/08/302000Jensen
62008/10/04100Nilsen

Now we want to find the sum of all "OrderPrice" fields".

We use the following SQL statement:

SELECT SUM(OrderPrice) AS OrderTotal FROM Orders


The result-set will look like this:

OrderTotal
5700

No comments:

Post a Comment