I'm want to get the
completed orders amount, and the
rejected orders count in 1 query. Please see my code below. How can I add where or condition inside the DB::raw()?
return DB::table('restaurants') ->join('orders', 'restaurants.id', 'orders.restaurant_id') ->select([ DB::raw('SUM(orders.total) WHERE status = 8 as completed_sum'), DB::raw('COUNT(DISTINCT(orders.transaction_code)) WHERE status = 3 as rejected_count') ]) ->get();
SQLSTATE: Syntax error or access violation: 1064 You have an error in your SQL syntax;