0
I have two tables:
table_entries
| id | descricao | quantidade |
| 1 | Maquina Prensa | 1 |
| 2 | Maquina Secadora | 2 |
table_bom_entries
| id | id_itens | codigo | quantidade |
| 1 | 1 | mp001 | 1 |
| 2 | 1 | mp002 | 2 |
| 3 | 1 | fx001 | 1 |
| 4 | 1 | fx002 | 5 |
| 5 | 2 | ms001 | 1 |
| 6 | 2 | ms002 | 2 |
| 7 | 2 | ms003 | 1 |
| 8 | 2 | ms004 | 1 |
| 9 | 2 | fx001 | 4 |
| 10 | 2 | fx002 | 1 |
I’m performing the following consultation:
SELECT
SUM(tb.quantidade*quantidade)
FROM
tabela_bom_itens
GROUP BY
codigo;
What is to happen to tabela_itens
is the parent product, and in tabela_bom_itens
would be the children.
In the tabela_bom_itens
would be the amount of parts going to each parent item.
So to know the amount of parts going into the parent product was to multiply the amount of parent product for each child product, and, if the same items appear in the two, group and inform the value of the sum of the items.
The expected result is:
| codigo | quantidade |
| mp001 | 1 |
| mp002 | 2 |
| ms001 | 2 |
| ms002 | 4 |
| ms003 | 2 |
| ms004 | 2 |
| fx001 | 9 |
| fx002 | 10 |
But what is returning has nothing to do, what is wrong with my query?
Junction, sum and grouping. These are the concepts that are necessary for the answer of your question
– Jefferson Quesado