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()'你的查詢來調試它。 –