【发布时间】:2021-07-16 14:35:47
【问题描述】:
我需要对最新的 1000 条记录使用count() 方法。
例如,我们有 3 个用户:
- 拥有 900 条记录的用户 A
- 拥有 20.000 条记录的用户 B
- 用户 C 有 10 条记录
现在我想只考虑最近的 1000 条记录进行计算,这意味着用户 A 和 C 将使用他们的所有记录,因为
// This should return for User A and C, 900 and 10, but for User C 1000
$recent_activities = Activity::select('id', 'user_id', 'activity')->where('user_id', $user->id)
->latest('id')->limit(1000)->count();
// The next 3 queries should analyse the recent 1000 records for occurences of certain %like% records and count them
$result_chat_refunds = Activity::where('activity', 'like', 'Credits erstattet%')->where('user_id', $user->id)
->latest('id')->limit(1000)->count();
$result_credit_membership = Activity::where('activity', 'like', '%Membership gutgeschrieben%')->where('user_id', $user->id)
->latest('id')->limit(1000)->count();
$result_credit_credits = Activity::where('activity', 'like', '%Credits gutgeschrieben%')->where('user_id', $user->id)
->latest('id')->limit(1000)->count();
我怎样才能做到这一点?
【问题讨论】: