Click here to Skip to main content
16,016,613 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Query to make a separate column to differentiate over by over difference?

create table test1(overs int,runs int)
insert into test1 values(1,10)
insert into test1 values(2,17)
insert into test1 values(3,20)
insert into test1 values (4,32)
insert into test1 values(5,38)

O/P
===
 Overs  runs  difference
  1     10     NULL
  2     17     7
  3     20     3 
  4     32     12
  5     38     6

What I have tried:

please any one give me the Query to achieve this above Requirement.
Posted
Updated 1-Jul-17 21:48pm

 
Share this answer
 
Try this:
SQL
SELECT Overs, Runs, Runs - LAG(Runs, 1, NULL) OVER (ORDER BY Overs) AS [Difference] FROM test1
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 2-Jul-17 4:45am    
For SQL 2012 and newer...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900