gpt4 book ai didi

php - Laravel orderby 查询与不同

转载 作者:行者123 更新时间:2023-12-03 17:03:20 27 4
gpt4 key购买 nike

我正在尝试通过 desc created_time 获取具有最新订单的唯一 thread_id

这是我的表样本。

===========================================
= id = thread_id = page_id = created_time =
===========================================
= 1 = 3 = 1 = 1551162660 =
= 2 = 1 = 1 = 1551162661 =
= 3 = 1 = 1 = 1551162662 =
= 4 = 2 = 1 = 1551162663 =
= 5 = 3 = 1 = 1551162664 =
= 6 = 1 = 1 = 1551162665 =
===========================================

这是我的代码。
DB::table('table_a')->select('thread_id')->orderBy('created_time', 'desc')->where('page_id', $page_id)->distinct()->get();

我的代码现在的问题是,它跳过了最新的 created_time 因为不同的..

正确的做法是什么?

最佳答案

尝试使用 group by 而不是 distinct

DB::table('table_a')
->select('thread_id')
->orderBy('created_time', 'desc')
->where('page_id', $page_id)
->groupBy('thread_id')
->get();

关于php - Laravel orderby 查询与不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54879942/

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