Hi want to find the difference between the the first value in each group with the preceding valueo/p shud be 1,a,10,10 1,a,5,-5 1,a,15,5 1,a,20,10 and so on.....declare @tbl as table(id int identity(1,1),groups varchar(5),value int)insert into @tblselect 'a',10 union allselect 'a',5 union allselect 'a',15 union allselect 'a',20 union allselect 'b',10 union allselect 'b',100I have came up with thisselect * from @tbl t1outer apply(select top 1(groups),value from @tbl t2 where t1.id=t2.id+1 and t1.groups=t2.groups and ???? --- this part i cant understand on how to get first value from each group order by groups desc)t3
PBUH