count two fields of a table in php sql

-1

I have a table called matriculas_2018 and two fields one of courses and the other of specialty .

I want to put an accountant that tells me how many students of the THIRD-AVERAGE course correspond to the ADMINISTRATION specialty and another that does the same but with the specialty OF ACCOUNTING

  

I hope you can help me .. thanks

asked by Juan Antonio Gonzalez Rozas 14.12.2017 в 17:09
source

2 answers

1

This is how it should work:

SELECT 
    SUM(IF(cursos = 'TERCERO MEDIO' and especialidad = 'ADMINISTRACION ',1,0)) as suma_administracion
    SUM(IF(cursos = 'TERCERO MEDIO' and especialidad = 'CONTABILIDAD ',1,0)) as suma_contabilidad
FROM matriculas_2018;
    
answered by 18.12.2017 в 14:01
1

Without wanting to consult for a specific specialty and course it would be like this:

SELECT CONUT(*) AS cantidad_contabilidad FROM matriculas_2018 WHERE curso LIKE '%TERCERO MEDIO%' AND especialidad LIKE '%CONTABILIDAD%';

But if you want to count on each specialty, what you have is to group

SELECT especialidad , CONUT(*) AS cantidad_contabilidad FROM matriculas_2018 WHERE curso LIKE '%TERCERO MEDIO%' GROUP BY especialidad;

    
answered by 18.12.2017 в 14:07