link for expected result, after group by 'receiver_user_id' and recent time
我已经使用了laravel查询没有得到所有表数据: -
$sub = BaseMessagesHistory::select('messages_history.*')->orderBy('created_at','DESC');
$chats = DB::table(DB::raw("({$sub->toSql()}) as sub"))
->select('receiver_user_id',DB::raw('max(created_at) as recent_time'))
->where('sender_user_id',$userId)
->orwhere('receiver_user_id',$userId)
->groupBy('receiver_user_id')
->havingRaw('max(created_at)')
->latest()->get();
结果: -
我只得到“recent_time”和“receiver_user_id”
Ex pectation: - 我需要整个数据表不仅是“recent_time”和“receiver_user_id”
所以,可以请你帮我出
有什么帮助请帮帮我吗? –
**我只接收“recent_time”和“receiver_user_id”**,理由:' - > select('receiver_user_id',DB :: raw('max(created_at)as recent_time'))' –
不过,最好' - > toSql()'你的查询来调试它。 –