0
I am using the following command to get the daily total sale by way of payment! So as I present below it works perfectly:
" SELECT t.DataDocumento, SUM(t.Valor) Total " +
" FROM VendaCliente v " +
" LEFT JOIN TitulosVendas t ON t.TabelaId = v.VendaId " +
" WHERE v.Ativo = 1 AND t.Forma = '3' AND t.DataDocumento BETWEEN '31/01/2019 00:00:00' AND '31/01/2019 23:59:59'
" GROUP BY t.DataDocumento " +
" ORDER BY t.DataDocumento ";
This second way I need to include 2 more Join’s to filter the products! Ai that appears to doubt... the somatorio are in duplicity:
" SELECT t.DataDocumento, SUM(t.Valor) Total " +
" FROM VendaCliente v " +
" LEFT JOIN TitulosVendas t ON t.TabelaId = v.VendaId " +
" LEFT JOIN VendaClienteItens i ON v.VendaId = i.VendaCliente " +
" LEFT JOIN Produto p ON p.ProdutoId = i.Produto " +
" WHERE v.Ativo = 1 AND t.Forma = '3' AND t.DataDocumento BETWEEN '31/01/2019 00:00:00' AND '31/01/2019 23:59:59'AND p.ProdutoId = '33603'
" GROUP BY t.DataDocumento " +
" ORDER BY t.DataDocumento ";
You are sure that there is no field name before Formapg and Date Issue?
– anonimo
Can you put an example of the data that exists in all the tables that you are using in the query? It would help a lot in the analysis.
– João Martins
Do not use the product table, take from the Join , and for Vendaclienteitens (active test) try a subselect in the Where
– Motta
Hello friends! The fields 'Formapg and Dataemissao' were as variables... now I have edited for better understanding. The precise product table to filter the products...
– Mario Junior