I have the tables:
-- NORTE --
create table tb_indices_norte(
id_norte int not null auto_increment,
localidade varchar(30),
sem_epi int not null,
totOvos smallint,
num_pos smallint,
num_inst smallint,
ipo decimal(5,1),
ido decimal(5,1),
ano varchar(4),
primary key(id_norte)) default charset = utf8;
-- SUL --
create table tb_indices_sul(
id_sul int not null auto_increment,
localidade varchar(30),
sem_epi int not null,
totOvos smallint,
num_pos smallint,
num_inst smallint,
ipo decimal(5,1),
ido decimal(5,1),
ano varchar(4),
primary key(id_sul)) default charset = utf8;
-- LESTE --
create table tb_indices_leste(
id_leste int not null auto_increment,
localidade varchar(30),
sem_epi int not null,
totOvos smallint,
num_pos smallint,
num_inst smallint,
ipo decimal(5,1),
ido decimal(5,1),
ano varchar(4),
primary key(id_leste)) default charset = utf8;
-- OESTE--
create table tb_indices_oeste(
id_oeste int not null auto_increment,
localidade varchar(30),
sem_epi int not null,
totOvos smallint,
num_pos smallint,
num_inst smallint,
ipo decimal(5,1),
ido decimal(5,1),
ano varchar(4),
primary key(id_oeste)) default charset = utf8;
How do I make a SELECT that returns me to SUM (totOvos), SUM (num_pos), SUM (num_inst) between the 4 tables WHERE year = 'X' AND sem_epi BETWEEN 'Y' AND 'Z' GROUP BY sem_epi
I'm a beginner in SQL, I know I have to define the PRIMARY KEYS and the FOREIGN KEY, my problem is just right, how to define in the tables and how to create this SELECT.