| |

VerySource

 Forgot password?
 Register
Search
View: 1015|Reply: 6

Is there any such sentence, please enlighten me

[Copy link]

3

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-1 16:30:01
| Show all posts |Read mode
If I have an id now, I want to query the IDs that are adjacent to the id.
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-5-11 11:15:01
| Show all posts
select top 2 * from tablename where id <specify id order by id desc
select top 2 * from tablenam where id> specify id order by id
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-5-11 19:45:01
| Show all posts
select top number * from tablename where id <id order by id desc
select top number * from tablename where id> query id order by id
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-5-12 12:15:02
| Show all posts
--try


select top N * from tbName where id <'' order by id desc
union all
select * from tbName where id = ''
union all
select top N * from tbName where id> '' order by id
Reply

Use magic Report

0

Threads

40

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-5-12 19:15:02
| Show all posts
select * from tablename
where
id in (select distinct top range number [id] from tablename where id <refer to id order by id DESC)
or
id in (select distinct top range number [id] from tablename where id> refer to id order by id ASC)
Reply

Use magic Report

0

Threads

40

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-5-13 10:15:01
| Show all posts
select * from #temp
where
[id] in (select distinct top Range number [id] from #temp where [id] <refer to id order by [id] DESC)
or
[id] = Reference id
or
[id] in (select distinct top Range number [id] from #temp where [id]> Refer to id order by [id] ASC)
Reply

Use magic Report

0

Threads

40

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-5-13 17:45:02
| Show all posts
create table #temp
(id varchar (50)
)
insert into #temp
select '1' union all select '2' union all select '3' union all select '4' union all select '5' union all select '6' union all select '7' union all select '8'
select * from #temp
----------------------
id
1
2
3
4
5
6
7
8


Two digits before and after query
select * from #temp
where
[id] in (select distinct top 2 [id] from #temp where [id] <5 order by [id] DESC)
or
[id] = 5
or
[id] in (select distinct top 2 [id] from #temp where [id]> 5 order by [id] ASC)
-------------
id
3
4
5
6
7
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list