title: Query Builder summarize the field value depending on another field
body: <p>I have some table
  <a href="https://i.stack.imgur.com/6dOfi.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6dOfi.jpg" alt="my some table"></a></p>
  
  <p>I need select an group iformation from these, but a have some conditions:</p>
  
  <ul>
  <li>Group results by date (day). Ideally when day start on 09.00 and finsh 09.00 (24hr)</li>
  <li>Then i need summarize values field <code>sum</code> where <code>'satus_id'</code> = 10 into new variable example <code>'TotalIn'</code> and where <code>status_id</code> = 12 into variable example <code>TotalOut</code></li>
  <li>Give results on view (but this no problem)</li>
  </ul>
  
  <p>How to do it?
  I write this, but i now this is wrong:</p>
  
  <pre><code>$statistic =   DB::connection('mysql2')-&gt;table('payout_transactions')
          -&gt;selectRaw('*, DATE(date) as day')
          -&gt;where('status_id', 12)
          -&gt;selectRaw('SUM(sum) AS TotalIn')
          -&gt;groupBy('day')
          -&gt;get();
  </code></pre>