Show different rows in the same query

0

Hi guys I have a problem with a mysql query, maybe it's super simple but I need a push to get it out.

It is a table of student registrations in which each student has different status such as "Registered", "Canceled", "Pending", "In Process".

What I want to do in the same query shows me a row of how many there are in registered status, another row how many are in canceled and so on.

    
asked by Axel Chavez 19.09.2018 в 19:44
source

1 answer

4

I would recommend you do it vertically instead of horizantal as you specify but to make it horizontal the most direct way with mysql is using sub-querys.

Example:

SELECT (SELECT COUNT(*) FROM tablaX WHERE status ='Registrado') AS Registrado, (SELECT COUNT(*) FROM tablaX WHERE status ='Cancelado') as Cancelado, (SELECT COUNT(*) FROM tablaX WHERE status ='Pendiente') as Pendiente, (SELECT COUNT(*) FROM tablaX WHERE status ='En Proceso') as "En Proceso"
    
answered by 19.09.2018 / 19:55
source