I need only one final value, the commission amount for products with extra commission in a date range and a specific vendor, the information is in 3 tables in the DB:
Below is the table 'products_commission_extra', the column 'Data_abertura' shows when the product began to have extra commission, and 'Closing_Date' when left unused, the value column is how much commission is earned per unit sold that if you put extra commission on a product it creates a new registry instead of changing the old one, to be able to have a history)
ThisistheSalesItems,itshowsthesalesproducts
Andthisisthesales(employeeIDanddateofsalestayhere)
SofarthecodeIwrotewiththehelpwasasfollows:
SELECTitens_venda.Id_produto,Quantidade,Valor,Id_funcionario,data_vendaFROMgenius.Itens_vendaJOINgenius.vendasONitens_venda.Id_venda=vendas.IdJOINprodutos_comissao_extraONprodutos_comissao_extra.Id_produto=itens_venda.Id_produtoWHEREdata_vendaBETWEENData_aberturaANDifnull(Data_fechamento,curdate())ANDId_funcionario=5ORDERBYData_fechamentoDESC;
Theresultisthis:
It's almost what I need, just need to filter by a specific date range, for example, I want only the month 7, but have to follow everything that has already been written in the code, I just have to filter the result that I already I have