title: How to optimize sum in MySQL
body: <p>i have a code to sum total cash from transaction like this,</p>
  
  <pre><code>public function get_total_cash($date_from, $date_to){
          $filtered_order = array('Ordered', 'Validated','Awaiting Packing','Packing Process','Ready to Ship','Shipped','Completed');
          $op_status = array('settlement','capture');
  
          $this-&gt;db-&gt;select('CAST(SUM(op_total) AS int) as total');
          $this-&gt;db-&gt;from("(dashboard_sales)");
          $this-&gt;db-&gt;where('order_date &gt;=', date('Y-m-d 00:00:00',strtotime($date_from)));
          $this-&gt;db-&gt;where('order_date &lt;=', date('Y-m-d 23:59:59',strtotime($date_to)));
          $this-&gt;db-&gt;where_in('order_status',$filtered_order);
          $this-&gt;db-&gt;where_in('op_status',$op_status);
          $query = $this-&gt;db-&gt;get();
          return $query-&gt;result()[0]-&gt;total;
      }
  </code></pre>
  
  <p>but the problem is that the transactions on my website have been overwhelming and when I extracted the code it became long. Transactions on my database are more than 25 thousand data.</p>
  
  <p>how to make the sum process is more optimize in my case?</p>