Laravel查询订单inrandormorder查询
我的桌子上有40行,我想要的是随机获取20行,然后按ID订购这5个列表;这2个查询;
例如,ID 1至40的范围;我从随机顺序15 10 14 9 3中获得;因此,在最终结果中,我希望得到3 9 10 14 15,
我尝试同时使用inrandomorder和orderby,
$query->inRandomOrder()->orderBy('id', 'asc')
但是inrandomorder查询总是对查询的最终执行;如果我切换他们的位置:
$query->orderBy('id', 'asc')->inRandomOrder()
订单始终具有最终执行
I have 40 rows in my table, what i want is to get 20 row randomly, and after order these 5 list by id; these 2 in one query;
for example in range of id 1 to 40; i get from the random order 15 10 14 9 3;so in the final result i expect to get 3 9 10 14 15
i tried to use inRandomOrder and orderBy in same time
$query->inRandomOrder()->orderBy('id', 'asc')
but the inRandomOrder query always has the final execution of my query; and if i switch their position:
$query->orderBy('id', 'asc')->inRandomOrder()
the orderBy always has the final execution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
2我猜想,如果您仅操纵数十行行,则可以使用Laravel Collection订购ID您的查询结果。
只需使用:
或使用SQL查询,您可以使用此查询:
您可以直接以雄辩的方式或SQL进行翻译。
我不一定会理解您的问题,btw: 通过ID 订购这5个列表?你到底是什么意思?
2 solutions I guess, if you manipulate only dozens of rows, you can use Laravel collection to order by ID your query result.
Just use:
Or using SQL query, you can use this query:
You can translate in Eloquent way, or as SQL directly.
I am not sure to understand your question btw: order these 5 list by id ? What do you mean exactly ?