mercredi 2 janvier 2019

Laravel Select DB raw sum with where clause not work

I am trying to retrieve my result and every day every service have how much total charged, total refund. My logic not work properly cause of where condition.I cant understand.

My code

    $transactions = Transaction::with('service')
        ->select('id','transaction_no','created_at','service_id')
        ->selectRaw(DB::raw('sum(deducted) as success where refund = 0'))
        ->addSelect(DB::raw('sum(charges) as charges'))
        ->addSelect(DB::raw('sum(deducted) as refunded where refund != 0'));
    $transactions = $transactions->groupBy('service_id',DB::raw('DATE(created_at)'))->get();
    return $transactions->toJson(JSON_PRETTY_PRINT);

I think issue is where refund != 0' and where refund = 0'



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire