How to sum based on a condition

Posted 2 years ago by Khudadad

Hi, all. I want to sum a field in the database(via query builder) based on a condition (ie. date<6/11/2016) and don't know which way is the best. I'm doing like this, is there any other better way to do this.

    $income = DB::table('incomes')
            ->join('currencies', 'currencies.cur_id','=','incomes.currency_id')
            ->selectRaw('incomes.*, currencies.currency ,sum( as total')
        return view('', compact('income','sd','ed'))->render();


Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.