开发者

Want the data of Upline and Downline for particular ID

开发者 https://www.devze.com 2022-12-16 22:35 出处:网络
here is the table and data like: id name 1test1 2test2 3test3 4test4 5test5 6test6 From above data i want the data like

here is the table and data like:

id name
1  test1
2  test2
3  test3
4  test4
5  test5
6  test6

From above data i want the data like if i pass the id as parameter and return the data from from up and gown by order

Example if i pass the id as parameter = 4 then it should be return upline 2 row and downline 2 row for particular id, and it should be like this

id name

2  test2
3  test3
4  test4
5  test5
6  t开发者_如何学Pythonest6

and same for the id = 3

id name
1  test1
2  test2
3  test3
4  test4
5  test5


SELECT TOP 3 id, name FROM table WHERE id =< @id ORDER BY id DESC

UNION 

SELECT TOP 2 id, name
FROM table
WHERE id > @id 
ORDER BY id ACS
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号