Tuesday, January 16, 2018

How To Use Sum() Functionality In Mssql

Hello Friend Today In This Blog I Will Show You How To Use Sum() By Functionality In Mssql.The SUM() function returns the total sum of a numeric column.The SQL SUM function is used to return the sum of an expression in a SELECT statement.This SQL tutorial explains how to use the SQL SUM function with syntax and examples.SQL SUM function is used to find out the sum of a field in various records.In this tutorial, you will learn how to use the SQL SUM function to calculate the sum of  all values or distinct values.SUM is a SQL aggregate function that totals the values in a given column. Unlike COUNT, you can only use SUM on columns containing numerical values.An important thing to remember: aggregators only aggregate vertically. If you want to perform a calculation across rows, you would do this with simple arithmetic.The SQL SUM function is an aggregate function that returns the sum of all or distinct values. We can apply the SUM function to the numeric column only.The SQL SUM() function is used to return the total of all values in the specific table column. The syntax is:SELECT SUM(column_name) FROM table_name;


Let’s say that we want to determine the total value of sold albums from the Album table. We can use the following SQL SUM() statement:SELECT SUM(sell) FROM album;.SUM function returns total sum of a selected columns numeric values.The SUM function returns the sum of the input column or expression values. The SUM function works with numeric values and ignores NULL values.


SUM() Syntax

SELECT SUM(column_name)
FROM table_name
WHERE condition;


Here Is An Example Related To Topic

Step 1 :Create database




Create database MNC




Step 2:Create table

Here In This step We Will Create table.

Here In This Step We Required Four Column With Name Uids ,Uname ,Ucountry and Usalary using Parameter bigint,varchar and float.

create table UserDetailinfo
(
Uids bigint,
Uname varchar(50),
Ucountry varchar(200),
Usalary float
);





Step 3 :Create Insert Trigger Functionality

Here In This Step We Will Insert Data Using Insert Command.
Data Will Be Added Manually Using Insert Command.


Insert Into UserDetailinfo values(1,'VIRAJ','INDIA',15000.00)
Insert Into UserDetailinfo values(2,'RAJ','USA',10000.00)
Insert Into UserDetailinfo values(3,'ANIL','UK',12000.00)
Insert Into UserDetailinfo values(4,'SUNIL','CANEDA',9000.00)
Insert Into UserDetailinfo values(5,'SHERYAS','CHINA',11000.00)
Insert Into UserDetailinfo values(6,'AJAY','CHINA',16000.00)


select *from UserDetailinfo





Step 4 :Create Sum() Functionality 

Here In This Step We Will Sum() Data Using Where Clause By Using Sum() Functionality .
Data Will Be Added Manually Using Sum() Functionality.
Here Data Will Be Sum By Using Sum() Functionality By Passing Column Name Ucountry='CHINA'.


SELECT SUM(Usalary) As SALARYSUM
FROM UserDetailinfo
WHERE Ucountry='CHINA';




HERE IS THE VIDEO RELATED TO TOPIC



No comments:

Post a Comment