2
I’m having difficulty in performing a query between 4 tables, being them. States > Municipalities > Deaths > Population The query is returning the value of the population with a larger number than the real one... Can anyone help me regarding this query?
select estados.nome, sum(obitos.quantidade) as Obitos,
sum(populacao.quantidade) as Pupolação
from estados
inner join municipios on (estados.idEstado = municipios.idEstado)
inner join obitos on (municipios.idMunicipio = obitos.idMunicipio)
inner join populacao on (municipios.idMunicipio = populacao.idMunicipio)
where obitos.data between '2008-01-01' and '2008-12-01'
and populacao.data = '2008-01-01'
GROUP BY estados.nome;
In this consultation I will sum up all populations of my municipalities and return the total by states, along with the number of deaths of the states. Follows the ER model:
How are the data from this date field in the table ?
– Diego Souza
It is as date in all tables... I put the ER model in question...
– Marcelo Henrique Casali
as far as I remember you can’t make 2 SUMS u Counts in different tables in the same query you’ll have to give a Union in two different and separate querys.
– Jasar Orion