0
Problem:-Add lines that have equal years via mysql command.
Query I am 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 are generated many equal years. Is there any way to add these productivity and present a line with each year? Photo example the expected result is:
productivity|Year 50 |2010 50 |2011
uses a group by year
– Adir Kuhn
You can use GROUP BY;
– Rafael Withoeft
SELECT SUM(productivity) Productivity, year.... WHERE .... GROUP BY year;
– ramaral
Group By it does not perform the sum. @ramaral but this is another query? or is saying to join what is there?
– Rodolfo Oliveira
This is your query with SUM and GROUP BY added.
– ramaral