As I exemplify in SQL Fiddle , I need to give the tables the data to be returned as follows: / p>
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 description will be returned as a product containing a cost average, the sum of its inputs and outputs, and the last release date. In SQL Fiddle, it contains what I could do.