I have a field in my database (dt_nf) which is type DATE. I would like to do a query that groups not by date, but by month and year, but I can not. My code looks like this:
SELECT
Sum(sjy_vendas.qtv) AS qt,
Sum(sjy_vendas.rprd) AS rec,
Sum(rprd-tprd-vlr_compra) AS lucro
FROM sjy_type
INNER JOIN sjy_empresas
INNER JOIN sjy_vendas ON sjy_empresas.id_empresa = sjy_vendas.empresa
AND sjy_type.id_tipo = sjy_vendas.tipo
WHERE sjy_type.dep='1'
AND sjy_empresas.grupo='$grupo'
AND sjy_vendas.dt_nf BETWEEN '$inicio' AND '$final'
AND sjy_vendas.empresa LIKE '$emp'
GROUP BY MONTH(sjy_vendas.dt_nf) AS dt_nf
ORDER BY sjy_vendas.dt_nf