Sql Tutorial Class


select sum in sql server

Select sum in SQL server.


How to use sum aggregate function in SQL Server: Sum aggregate function is used to add the numbers in SQL table. The sum can also use with SQL Select where command. If SQL sum function used without SQL Select Where command than display the sum of all records. 

Syntax:
        Select sum[COLUMN_NAME] From [TABLE_NAME]

Description:
              Select: SQL keyword.
         sum: Aggregate function of SQL Server.
         [COLUMN_NAME]: Column name of Table.
         From: SQL keyword.
         [TABLE_NAME]: Name of Table.

Example: 
         Select Sum(ItemQuantity) From ItemDetails

         [NOTE: ItemDtails is a table which created in previous topic. More details click here]

Sum aggregate function in Image:

select sum in sql server








SUM Aggregate function with SQL Select where command:


Syntax:
         Select sum[COLUMN_NAME] From [TABLE_NAME] Where [COLUMN_NAME] [OPERATORS] ['VALUE']

Description:
       Select: SQL Command.
      Sum: Aggregate function of SQL Server.
      [COLUMN_NAME]: Column of Table.
      From: SQL Command.
      [TABLE_NAME]: Name of Table.
      Where: SQL Where Command.
      [OPERATORS]: Operators of SQL Server. (=,  >, >=, <, <=)
      ['VALUE']=User define value.

Example:
            Select SUM(ItemQuantity) from ItemDetails Where ManufactureCompany='Samsung'
            [NOTE: ItemDtails is a table which created in previous topic. More details click here]

SUM aggregate function in SQL Select where statement, in Image


SUM in sql select statement



No comments:

Post a Comment