I have following table i wants sum of all orders_qty in between two years & in two month. I am creating query as following which display only answer 4 and actual wants result 8(2,2,2,2)
orders_id orders_qty delivery_date
1 2,2, 2019-02-01
2 2,2, 2020-02-03
controller:getting qty addition month wise
$get_month_wise_details=DB::table('orders')
->select('orders_qty')
->where('order_status',6)
->whereBetween(DB::raw('DATE_FORMAT(deliver_date,"%Y-%m")'), ['2019-02','2020-02'])
->groupBy('orders_qty')
->get();
foreach ($get_month_wise_details as $month_wise_details)
{
$month_array=explode(',',$month_wise_details->orders_qty);
$month_addition=array_sum($month_array);
$sum_qty=$sum_qty+$month_addition;
}
controller:getting qty addition year wise
$get_year_wise_details=DB::table('orders')
->select('orders_qty')
->where('order_status',6)
->whereBetween(DB::raw('DATE_FORMAT(deliver_date,"%Y")'), ['2019','2020'])
->groupBy('orders_qty')
->get();
foreach ($get_year_wise_details as $year_wise_details)
{
$year_array=explode(',',$year_wise_details->orders_qty);
$year_addition=array_sum($year_array);
$sum_qty=$sum_qty+$year_addition;
}