sql循环并设置属性
在SQL中,我想查询一个列表,按pageNumber排序
SELECT * FROM `comics`
WHERE 1
ORDER BY pageNumber ASC
然后,我想根据查询中的索引设置它们的pageNumbers(从1而不是0开始)。
这是我所需功能的伪代码;其中list是上面Select Query的返回值。
for(var n:int = 0; n<list.length; n++){
if(list[n].pageNumber != n+1){
list[n].pageNumber = n+1
}
}
例如,我可能有 pageNumbers 5, 17, 23, 24, 18, 7
ORDER BY pageNumber ASC 会将其排序为 5, 7, 17, 18, 23, 24
>
然后我想将页码更改为 1, 2, 3, 4, 5, 6
编辑:
@fortheworld MySQL
@cyberkiwi UPDATE
很抱歉不清楚。我想我需要了解更多才能让我的问题清楚:) 感谢你的帮助
In SQL, I would like to query a list, in order by pageNumber
SELECT * FROM `comics`
WHERE 1
ORDER BY pageNumber ASC
Then, I would like to set their pageNumbers based on their index in the query (starting with 1 instead of 0).
Here is my pseudo code for the functionality as desired; where list is the return value of the Select Query above.
for(var n:int = 0; n<list.length; n++){
if(list[n].pageNumber != n+1){
list[n].pageNumber = n+1
}
}
For example I might have pageNumbers 5, 17, 23, 24, 18, 7
The ORDER BY pageNumber ASC will sort this to 5, 7, 17, 18, 23, 24
I would then like to alter the pageNumbers in order to be 1, 2, 3, 4, 5, 6
edit:
@fortheworld MySQL
@cyberkiwi UPDATE
sorry for being unclear. guess i need to learn more for my questions to be clear :)
thanks for all your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白为什么人们坚持编写一条 SQL 批处理,而一条语句就可以了。
I don't understand why peops insist on writing an SQL batch when a single statement will do.