Sai Reddy

Sai Reddy

  • NA
  • 214
  • 30.9k

Above and below values of a id

Feb 11 2019 11:48 PM
 Hi ,Please help me to solve it.
 
 
create table sample
(
ID int IDENTITY,
country varchar(10),
UNI int,
)
insert into sample values('INDIA',1000),('INDIA',1001),('INDIA',1002),('INDIA',1003),('INDIA',1004),('INDIA',1005),
('AUS',1001),('AUS',1002),('AUS',1003),('AUS',1004),('AUS',1005),('US',1001),('US',1002),('US',1003),('US',1004);
select * from sample; 
 
When i pass the particular id from one group of countr i need the 2 above and 2 below of passed number from the same country.
Ex: if i pass the id=9 then result should be as follows
7 AUS 1001
8 AUS 1002
9 AUS 1003
10 AUS 1004
11 AUS 1005
 

Answers (4)