TSQL,按ID选择记录,前3个和下3个,共7个 [英] TSQL , Select records by ID, 3 previous and 3 next, total of 7

查看:92
本文介绍了TSQL,按ID选择记录,前3个和下3个,共7个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这是有道理的.

我想按零件号选择一个记录范围,但是要有3个先前的记录,实际的当前记录和3个接下来的记录.就像看着自动点唱机,您可以看到上一页,当前页和下一页.

03-380-上一个
03-390-当前
03-400-下一条记录

我什至想不出要搜索的单词,现在已经尝试了一段时间.

I hope that made sense.

I want to select a range of records, by Part Number, but instead have 3 previous records, the actual current record, and 3 next records. Sort of like looking at the Jukebox, and you can see the previous page, current page, and next page.

03-380 - Previous
03-390 - current
03-400 - Next Record

I can''t even think of the words needed to search for this, been trying for awhile now

推荐答案

http://www.databasejournal.com/features/mssql/article.php/3572301/RowNumber-function-in-SQL-Server-2005.htm[^] should help. You can do queries based on the row number, so you can find the row number of your record, then select based on row number before and after.


这篇关于TSQL,按ID选择记录,前3个和下3个,共7个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆