Select SUM buscando dados de 2 tabelas diferentes ?

Delphi

Banco de Dados

18/01/2017

Bom dia ,
Gostaria de saber como faço esse select !
Desde já agradeço
Rodrigo Oliveira

Rodrigo Oliveira

Curtidas 0

Respostas

Gabriel Baltazar

Gabriel Baltazar

18/01/2017

Acho que terá que ser mais específico com sua dificuldade....

SELECT SUM(TABELA1.CAMPO) AS TOTAL FROM TABELA1 JOIN TABELA2 ON TABELA1.CODIGO = TABELA2.CODIGOTABELA1
GOSTEI 0
Deivid Nascimento

Deivid Nascimento

18/01/2017

se existe relacao vc pode usar inner join

select sum(t1.campo),sum(t2.campo) from tabela1 as t1
inner join tabelas2 as t2 on t2.id=t1.tabela2_fk
GOSTEI 0
Rodrigo Oliveira

Rodrigo Oliveira

18/01/2017

esse t1 e t2 seria o nome da minha tabela ?
GOSTEI 0
Deivid Nascimento

Deivid Nascimento

18/01/2017

sim, sao alias das tabelas
GOSTEI 0
POSTAR