Add lines with the same year

0

Problem: - Take the lines that have equal years through the command in mysql.

Query that I'm using:

SELECT produtividade, ano
FROM area_e_producao_05_15
INNER JOIN dados_cidades
ON edr_id={$edr['edr_id']}
WHERE area_e_producao_05_15.id_municipio=dados_cidades.dados_cidades_id AND Ano BETWEEN {$ano} and {$ano2} Order By Ano

My result was:

In this case the result was little, but in some cases many years are created equal. Is there any way to add these productivities and present a line with each year? Example of the photo the expected result is:

Productivity | Year 50 | 2010 50 | 2011

    
asked by anonymous 24.02.2015 / 19:39

1 answer

2

Try this:

 SELECT sum(produtividade), ano
   FROM area_e_producao_05_15
  INNER JOIN dados_cidades
     ON edr_id={$edr['edr_id']}
  WHERE area_e_producao_05_15.id_municipio=dados_cidades.dados_cidades_id 
    AND Ano BETWEEN {$ano} and {$ano2} 
  GROUP BY ano
  ORDER BY ano
    
24.02.2015 / 20:02