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
精彩评论