旋转表数据而不更新数据
SELECT * FROM `your_table` LIMIT 0, 10
->这将显示第一个 1,2,3,4,5,6,7,8,9,10
SELECT * FROM `your_table` LIMIT 5, 5
->这将显示记录 6,7,8,9,10
我想显示数据 2, 3,4,5,6,7,8,9,10,1 和 第二天 3,4,5,6,7,8,9,10,1,2 后天 4,5,6,7,8,9,10,1,2,3
是否可以不更新此表的任何数据???
SELECT * FROM `your_table` LIMIT 0, 10
->This will display the first 1,2,3,4,5,6,7,8,9,10
SELECT * FROM `your_table` LIMIT 5, 5
->This will show records 6, 7, 8, 9, 10
I want to Show data 2,3,4,5,6,7,8,9,10,1 and
next day 3,4,5,6,7,8,9,10,1,2
day after next day 4,5,6,7,8,9,10,1,2,3
IS IT POSSIBLE with out updating any data of this table ???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 UNION 语法来完成此操作:
这将首先选择限制范围内的行,然后合并第二次选择的剩余行。请注意,您不需要对第二个 select 语句设置限制:
You can do this using the UNION syntax:
This will first select rows within your limit, and then combine the remainder from the second select. Note that you don't need to set a limit on the second select statement:
我不认为使用简单的 Select 可以实现这一点(我可能是错的)。我想你需要一个存储过程。
I don't think this might be achieved using a simple Select (I may be wrong). I think you'll need a stored procedure.
您已将其标记为 Oracle,尽管您的 SQL 语法对 Oracle 无效,因为它不支持 LIMIT
但是,这里有一个适用于 Oracle 的解决方案:
其中 :startRows 和 :limitRows 是 LIMIT 的值,并且: baseRef 是一个介于 0 和 :limitRows-1 之间的值,应该每天递增/循环(即,在第 1 天,它应该为 0;在第 2 天,1;在第 10、9 天;在第 11 天,您应该恢复为0)。您实际上可以使用当前日期,转换为 Julian 并除以 :limitRows 时取余数以自动计算 :baseRef
(根据需要替换您自己的列和表名称)
You've tagged this as Oracle, though your SQL syntax would be invalid for Oracle because it doesn't support LIMIT
However, here's a solution that will work in Oracle:
where :startRows and :limitRows are the values for your LIMIT, and :baseRef is a value between 0 and :limitRows-1 that should be incremented/cycled on a daily basis (ie on day 1 it should be 0; on day 2, 1; on day 10, 9; on day 11 you should revert to 0). You could actually use the current date, converted to Julian and take the remainder when divided by :limitRows to automate calculating :baseRef
(substitute your own column and table names as appropriate)
好吧,对于问题的作者来说可能有点晚了,但对人们来说可能有用。
简短回答:可以像作者要求的那样进行“旋转”。
长答案:[我将首先解释 MySQL - 我在哪里测试这个]
让我们假设我们有表 your_table (INT rn, ...)。您想要的是以特定方式排序(从 rn=N 开始“旋转”)。排序的第一个条件是 rn >= N desc。这个想法(至少我是如何理解的)是我们将顺序从 asc 更改为 desc 并将表格分成两部分(=N) 。然后我们按 rn 但 asc 顺序对其进行排序。它将独立地对每个组执行排序。所以这是我们的查询:
如果你没有 rn 列 - 你总是可以使用带有参数的技巧,但
我不知道最后一个是否有效。
对于 Oracle,您始终可以使用 rownum。而且我相信你也会得到同样的结果(我没有测试过!)。
希望有帮助!
Well, it might be a little bit late for the author of the question, but could be useful for people.
Short answer: It is possible to do the "spin" like author asked.
Long answer: [I'm going to explain for MySQL first - where I tested this]
Let's imagine that we have table your_table (INT rn, ...). What you want is to sort in specific way ("spin" with beginning at the rn=N). First condition of ordering is rn >= N desc. The idea (at least how I understand this) is we change the order from asc to desc and split our table in two parts (<N and >=N). Then we order this back by rn but asc order. It will execute sorting for each group independently. So here is our query:
If you don't have rn column - you always can use the trick with parameter
I don't know if the last one is efficient, though.
For Oracle, you always can use rownum. And I believe that you will have the same result (I didn't test it!).
Hope it helps!