title: Getting average from database in laravel 4
body: <p>I have two tables: Workplans and Progress. Here is the Workplan table.</p>
  
  <p><strong>Workplan Table:</strong></p>
  
  <p>id </p>
  
  <p>division_name</p>
  
  <p>division_chief</p>
  
  <p><strong>Progress Table:</strong></p>
  
  <p>id</p>
  
  <p>score</p>
  
  <p>workplan_id      <strong>foreign_key</strong></p>
  
  <p>Here workplan_id is foreign key of workplan table.</p>
  
  <p>Now I want to get average from progress table grouping by the division_name. But I am really messed up with my query. What is I have done:</p>
  
  <pre><code>  $report = DB::table('workplans')
      -&gt;join('progress','workplans.id','=','progress.workplan_id')
      -&gt;avg('progress.score')
      -&gt;groupBy('workplans.division_name')
      -&gt;get();
  
    dd($report);
  </code></pre>