gpt4 book ai didi

mysql - 我的 SQL 查询有什么问题?

转载 作者:行者123 更新时间:2023-11-29 05:12:05 25 4
gpt4 key购买 nike

select * from `a2_posts` where `reply_to` = -1 order by `updated_at` desc offset 4;

我收到这条消息:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'offset 4' at line 1

我不是 sql 专家,但我真的搞不懂偏移量有什么问题。

顺便说一句,这个查询是由 Eloquent ORM 生成的,来自这段代码:

Post::whereReplyTo($request->input('reply_to'))
->orderBy('updated_at', 'desc')
->offset(Config::PAGE_SIZE * Config::MAX_PAGES)
->get();

我只是将结果查询输入 PHPMyAdmin 以检查发生了什么,这就是我得到的

你们知道这是怎么回事吗? PHPMyAdmin 荧光笔甚至没有突出显示 offset 关键字。

提前致谢

最佳答案

MySQL syntax requires LIMIT x before OFFSET x.

语法:

[LIMIT {[offset,] row_count | row_count OFFSET offset}]

它需要是这样的:

select * from `a2_posts` where `reply_to` = -1 
order by `updated_at` desc
limit 2 offset 4;

关于mysql - 我的 SQL 查询有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38056089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com