Saturday 9 April 2016

How to find running total in Sql Server 2012

How to find running total in Sql Server 2012

--create database which name testdb.............
create database testdb
use testdb
-- query for  create   table....
create table  Employee
(
EmpId int primary key,
Name varchar(50),
Gender varchar(50),
Salary int
)

insert into Employee (EmpId,Name,Gender,Salary) values(1,'Kiran Pal','Male',9000)
-- query 1 for  running total in Sql Server 2012
select Name,Gender,Salary,
SUM(Salary)over(order by EmpId)  from Employee
-- query 2 for  running total in Sql Server 2012 with  order by EmpId
select Name,Gender,Salary,
SUM(Salary)over(order by Salary)  from Employee
-- query 3 for  running total in Sql Server 2012 with partition
select Name,Gender,Salary,

SUM(Salary)over(Partition by Gender order by EmpId)  from Employee




0 comments:

Post a Comment