report in related tables (mysql)

Asked

Viewed 26 times

-1

Guys, I’m breaking into something super simple, but I don’t know where I’m going wrong

Let’s say I have the tables below, all related to each other

tabela1: nota_fiscal (id, data_emissao)
1 '2019-05-12'
2 '2019-02-02'
3 '2019-05-05'

tabela2: itens (id, descricao)
1 'vestuario'
2 'comida'

tabela3: notafiscal_itens (id_nf, id_itens, valor_total)
1 2 50.00
1 1 100.00
2 2 70.00

need to select a SUM (total value) of the table notafiscal_items, WHERE id_items = 2 AND notafiscal.data_issued between ('2018-01-01' and '2018-12-31')

how would this select?

1 answer

3


Test this code and see if it works, and test without GROUP BY and see if it works anyway.

select SUM(nfi.valor_total)
from notafiscal_itens as as nfi
inner join notafiscal as nf on nf.id = nfi.id_nf
WHERE nfi.id_itens = 2
AND nf.data_emissao between '2018-01-01' and '2018-12-31'
GROUP BY valor_total
  • well straight, thanks, without the group by gave exactly what I needed, I was wrong in Ner Join

Browser other questions tagged

You are not signed in. Login or sign up in order to post.