2016-06-14 4 views
1
)

나는 쿼리를 사용하여 카운트를 사용해야하고 일반 쿼리를 사용해야합니다. Laravel에서Laravel DB 쿼리 (

select sum(total) as Total,AffID,user_id from Affiliates 
group by AffID order by user_id ASC 

정상

다음

foreach($result_array as $row) 
{ 
    echo $row['total']."<br/>"; 
    echo $row['AffID']."<br/>"; 
    echo $row['user_id ']."<br/>"; 
} 

내가

$affdata = DB::select('Affiliates') 
     ->whereRaw('CompletedDate >= curdate()') 
     ->groupBy('AffID') 
     ->orderBy('user_id', 'ASC') 
     ->sum('total'); 
     ->get(); 
foreach($affdata as $row) 
{ 
    echo $row->AffID ."<br>"; 
    echo $row->total ."<br>"; 
} 

을 시도하지만 오류를 던질 것으로 보인다. 총계 계산과 함께 AFFID를 반향시킬 필요가 있으므로

답변

0

이 올바른 쿼리

$affdata = DB::table('Affiliates')->select(DB::raw('sum(total) as total'), 'AffID', 'user_id') 
      ->whereRaw('CompletedDate >= curdate()') 
      ->groupBy('AffID') 
      ->orderBy('user_id', 'ASC') 
      ->get(); 
입니다
1

당신의 질의를 여기에 업데이트하십시오.

$affdata = DB::table('Affiliates')->select(DB::raw('sum(total) as total'), 'AffID', 'user_id')) 
      ->whereRaw('CompletedDate >= curdate()') 
      ->groupBy('AffID') 
      ->orderBy('user_id', 'ASC') 
      ->sum('total'); 
      ->get();