Lets say I have a database full of users. And a table filled with the "points" users have earned for various activities the Points table has these columns:
id, user_id, value, created_at, updated_at
I want to be able to get a user's total points, easy as pie using the ->sum() method, then compare that user's total points to the average user's total points.
I know that I can get a collection of each users total points via:
->groupBy('user_id')->selectRaw( "sum( value ) as sum" )->pluck( "sum" );
but I'm drawing a blank as to how to get the average total score across all users, instead of an array of each user's total score.
Thanks!