0
As exemplified in SQL Fiddle, given the tables, the data will be returned as follows:
nome | descricao| tipo | custo| ult_lancamento | entradas | saidas
---------------------------------------------------------------------------
ProdutoA | ProdutoA | ACABADO | 0.91 | May,12 2017 15:39:00 | 220 | 90
----------------------------------------------------------------------------
ProdutoB | ProdutoB | PRIMA | 1.25 | March,24 2017 07:40:00 | 50 | (null)
That is, products that have the same name and the same description will be returned as a product containing an average cost, the sum of their entries and their exits and the last release date. In SQL Fiddle, it contains what I was able to do.
his reply returned all products. Including those that had no launches. Also, the sum of the outputs was not made, note that the result was null. As for your comments, I am registering products that have the same name and description as there is the possibility of the same product being purchased from different suppliers and with different prices. As for the other two tips, I liked it.
– Marcelo Augusto
on the first observation, the second solves the problem of suppliers and different prices, store the supplier also in the table of movement if it is the case, then you stay with the normalized bank, will have a history of purchases, prices and suppliers for each product. About leaving the products that had no movement, there was nothing specifying that they should not leave, so I opted for the left Outer Join, just replace this clause by Inner Join. =]
– Rovann Linhalis
I returned to the Fiddle to see, only one product had 1 output, soon the others would leave as null same
– Rovann Linhalis
@Ronvann switched to Ner Jack, but nothing was returned. In Fiddle Produtoa had a way out, but in the final sum (made with left Outer Join) left as null. As for your tips, I would keep the price and supplier in Launches and remove from the product, right?
– Marcelo Augusto
I tried to open Fiddle to change the code and it gives sync error =/. And yes, in the same way that at launch you can have a customer to maintain the customer’s purchase history (Obs. I do customer and suppliers on the same table, only gets a FK in the table of releases)
– Rovann Linhalis
You are really making a mistake. Do you mind explaining to me this idea of the fields through the Angouts chat? At least we do not fill the post here and when we solve the sql query we post the answer.
– Marcelo Augusto
I have never used Angouts, just tell me how =] hehe, search for my name there that should appear
– Rovann Linhalis
It’s gmail chat. I sent you the invitation
– Marcelo Augusto