I'm breaking my head with a problem, I need the information from a column, constructed through query, to be transformed into a line (query header).
I saw some tutorials and related debts but could not implement:
- PIVOT - I could not implement mysql;
- CASE THEN - Initially gave right, the problem is that he continued to duplicate the lines by user,
SELECT
usuario,
op_nome,
CASE WHEN (YEAR(cl_data_cadastro)='2016' AND MONTH(cl_data_cadastro) ='1') THEN cl_idade ELSE NULL END AS '01/2016',
CASE WHEN (YEAR(cl_data_cadastro)='2016' AND MONTH(cl_data_cadastro) ='2') THEN cl_idade ELSE NULL END AS '02/2016',
CASE WHEN (YEAR(cl_data_cadastro)='2016' AND MONTH(cl_data_cadastro) ='3') THEN cl_idade ELSE NULL END AS '03/2016'
FROM
clientes
WHERE
cl_data_cadastro BETWEEN '2016-01-01' AND '2016-03-31'
GROUP BY op_usuario, YEAR(ct_data_cadastro), MONTH(ct_data_cadastro)