skip to Main Content
SELECT
    team_name,
    (CASE WHEN `assignment` = 'Appeal/Recon/Claim Review' THEN `done` ELSE 0 END) AS 'Appeal', 
    (CASE WHEN `assignment` = 'IDR' THEN `done` ELSE 0 END) AS 'IDR'
FROM
    operation_assignments  
WHERE
    serial = 6 
GROUP BY
    team_name
$collections = DB::table('operation_assignments')
    ->select(
        'team_name', 
        DB::raw("CASE WHEN assignment = 'Appeal/Recon/Claim Review' THEN done ELSE 0 END AS Appeal"),
        DB::raw("CASE WHEN assignment = 'IDR' THEN done ELSE 0 END AS IDR")
    )
    ->where('serial', 6)
    ->groupBy('team_name')
    ->get();

2

Answers


  1. Chosen as BEST ANSWER

    $collections = OperationAssignment::select(['team_name', DB::raw("SUM(CASE WHEN assignment='Appeal/Recon/Claim Review' THEN done END) as 'appeal'"), DB::raw("SUM(CASE WHEN assignment='IDR' THEN done END) as 'idr'"), ])->where('serial',6)->groupBy('team_name')->get();


  2. You don’t need to do anything. Eloquent extends the base query builder so the syntax is the same. The only difference is instead of DB::table('operation_assignments'), you use your model (I’m assuming it’s AppModelsOperationAssignment).

    # app/Models/OperationAssignment.php
    
    namespace AppModels;
    
    class OperationAssignment extends Model
    {
        protected $table = 'operation_assignments';
    
        ...
    }
    
    use AppModelsOperationAssignment;
    
    $collections = OperationAssignment::query()
        ->select(...)
        ->where(...)
        ->groupBy(...)
        ->get();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search