create table #temp1
(
userid int,
username varchar(50)
)
insert into #temp1
select 12,'siba'
union all select 13,'anurag'
union all select 13,'abhishek'
union all select 14,'ravi'
union all select 14,'anurag'
union all select 15,'siba'
union all
select 19,'siba'
select 12,'tom'
select userid,username,first_value(userid) over(order by userid desc) as firstvalue,last_value(userid) over(order by userid desc) as lastvalue
from #temp1
-------------------------------------------------------------------------
select userid,username,first_value(userid) over(order by userid desc) as firstvalue,last_value(userid) over(order by userid desc) as lastvalue,
lead(userid) over(order by userid asc) as leaduserid
from #temp1
-->Last_value is actually
the row currently which we are looking at and Lead is the subsequent row value
No comments:
Post a Comment