Sort Table Horizontally Mysql

0

I have the following query:

SELECT asunto, MONTH(created_at) as mes, COUNT(turno) as numero
FROM tikets
where id_sucursal = 1 and subasunto = 'Pago' GROUP BY asunto, mes ORDER BY mes ASC 

Which throws me the results like this:

I was wondering how I could do the consultation so that it would come out like this or what I would have to do. Thanks for your attention

    
asked by Esteban Flores 15.05.2017 в 18:49
source

3 answers

0

Your problem is not from the SQL query, but from how you sample the data, that is, the SQL query would be the same for both views and, therefore, also the data obtained. You simply have two different views (only the HTML construction and the applied styles vary).

    
answered by 15.05.2017 в 23:11
0

I clarify that I do not have data to confirm the result.

SELECT asunto, 
    COUNT(case when MONTH(created_at) = 2 then turno else 0 END) as FEB,
    COUNT(case when MONTH(created_at) = 3 then turno else 0 END) as MAR,
    COUNT(case when MONTH(created_at) = 4 then turno else 0 END) as ABR
FROM tikets
    where id_sucursal = 1 and subasunto = 'Pago' 
    GROUP BY asunto, mes 
    ORDER BY mes ASC
    
answered by 15.05.2017 в 22:48
0

There is something that is called pivot_table, I'm not sure if mySql has it, but it allows you to sort the table directly in the query and not from html or any programming.

I leave you these two tutorials for mySQL plays more or less arm from sql:

link link

I hope you will be a guide

    
answered by 16.05.2017 в 00:03