I am getting stuck on this i want the count the number of records but it returns me wrong value every time .Here is my table:-
id contributor_id user_id history_id contributor_income
1 1 14 1 0.57
2 1 14 2 0.57
3 1 14 3 0.57
4 1 14 4 3.75
5 2 14 5 0.57
Here above is my table but it gives me count 4 but i want 2. Here is my query :-
$query = DB::table('contributor_commissions')
->groupBy('contributor_id')->count();
But when i print this it gives count as 4 but there are only two groups of contributor_id
干得好:
$reserves = DB::table('contributor_commissions')->selectRaw('*, count(*)')->groupBy('contributor_id');
请试试这个
DB::table('contributor_commissions')->distinct('contributor_id')->count('contributor_id');
这应该工作DB::table('contributor_commissions')->distinct('contributor_id')->count()
Try this.
$query = $user_info = DB::table('contributor_commissions')
->select('contributor_id', DB::raw('count(*) as total'))
->groupBy('contributor_id')
->get();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.