MySQL doesn’t have those direct functions available, but it is possible to do that using CASE as in the following example:
1 2 3 4 5 6 7 | SELECT SUM ( CASE WHEN EI.activo = 'S' THEN 1 ELSE 0 END ) AS total_activos, SUM ( CASE WHEN EI.activo != 'S' THEN 1 ELSE 0 END ) AS total_removidos FROM core_items AS EI WHERE EI.id_ficha = 190; |
Result in this example will be similar to this:

Explanation: As the query iterates the SUM increments the value by 1 when the condition is met, otherwise it does not.
Here it is a Laravel ORM example:
1 2 3 4 5 6 7 8 | $sqlString = [ DB::Raw( "SUM(CASE WHEN activo = 'S' THEN 1 ELSE 0 END) AS total_activos" ), DB::Raw( "SUM(CASE WHEN activo != 'S' THEN 1 ELSE 0 END) AS total_removidos" ) ]; $result = Model::select( $sqlString ) ->where( "id_ficha" , $idFicha ) ->first(); |