count(*) over(order by no range between 2 preceding and 4 following)

select no, name, count(*)
over(order by no range between 2 preceding and 4 following) as sim_cnt
from pt_test

before -2 after 4 from your no


NO,NAME,SIM_CNT
-21,hello,1
1,hello2,4
4,hello2,3
4,hello,3
5,hello,3
10,hello,1

Comments

Popular posts from this blog

Project euler 169 found clue

Floyd-Warshall's algorithm