Member 13288167 Ответов: 2

Пожалуйста, дайте мне запрос на нижеприведенный требуемый вывод.


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.

2 Ответов

Рейтинг:
1

Kornfeld Eliyahu Peter

LMGTFY[^]


Рейтинг:
0

OriginalGriff

Попробовать это:

SELECT Overs, Runs, Runs - LAG(Runs, 1, NULL) OVER (ORDER BY Overs) AS [Difference] FROM test1


Kornfeld Eliyahu Peter

Для SQL 2012 и новее...