How do I make a select with sum
and inner join
to add a value x between 3 tables. A query
return to the lowest possible number of results.
create table credit_card (
credit_card_id int primary key,
nome varchar (30)
);
create table store (
store_id int primary key,
nome varchar (30)
);
create table sale (
id serial primary key,
data date,
valor numeric,
credit_card_fk int references credit_card (id),
store_id_fk int references store (id)
);
select * from store
select * from credit_card
select * from sale
DROP TABLE CREDIT_CARD CASCADE
I do not know how to do it:
select store.nome, store_id_fk, credit_card.nome, credit_card_fk, sale.valor, sale.data
from sale
inner join store on (store.id= sale.store_id_fk)
inner join credit_card on (credit_card.id= sale.credit_card_fk)
order by store