gpt4 book ai didi

php - 从特定的 where 子句中获取最高的 id

转载 作者:可可西里 更新时间:2023-11-01 00:41:18 25 4
gpt4 key购买 nike

我的客人数据库中有 4 条记录。

enter image description here

我正在尝试查询具有 note_display = 1 且具有最高 ID 的 guest 。


我试过了

$last_note = DB::table('guests')->where('note_display','=',1)->where('id', DB::raw("(select max(`id`) from guests)"))->first();

我得到了

Trying to get property of non-object

我现在有点卡住了,任何提示都会有很大的帮助吗?

最佳答案

在此查询中无需使用raw。您可以运行一个简单的查询,例如

Guest::where('note_display', 1)->orderBy('id', 'desc')->first();

它会返回具有最高 IDnote_display = 1 的 Guest。

关于php - 从特定的 where 子句中获取最高的 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36295655/

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