They passed me a system of a company to update, they have 3 MySQL tables 'vendaesc, venda, venda_forma_payagem'. From what I understand the vendaesc table is used to store the sales items.
I need to create a report that brings me the data of the product sold, quantity sold, unit value, total value of the sale, form of payment, parcels and the problem comes there, often in a single sale insert numerous products, there is a single form of payment for sale. The form of payment information is saved in the Sale table.
The structure of the tables: Sale
'id' int(11) NOT NULL AUTO_INCREMENT,
'Cod' varchar(10) NOT NULL DEFAULT '',
'Data' date DEFAULT NULL,
'Hora' varchar(50) NOT NULL DEFAULT '',
'Desconto' varchar(20) NOT NULL DEFAULT '',
'TotalS' double(10,2) NOT NULL,
'TotalC' double(10,2) NOT NULL,
'Cod_Cliente' varchar(20) NOT NULL DEFAULT '',
'Nome_Cliente' varchar(150) NOT NULL DEFAULT '',
'Mes' varchar(50) NOT NULL DEFAULT '',
'Ano' varchar(4) NOT NULL DEFAULT '',
'forma_pagamento' int(11) DEFAULT NULL,
'forma_pagamento_detalhe' int(11) DEFAULT NULL,
'forma_pagamento_detalhe_nome' varchar(40) NOT NULL DEFAULT '',
'forma_pagamento_parcelas' int(11) DEFAULT NULL,
PRIMARY KEY ('id')
Vendaesc
'Cod' varchar(20) NOT NULL DEFAULT '',
'Venda' varchar(10) NOT NULL DEFAULT '',
'CodTipo' varchar(10) NOT NULL DEFAULT '',
'Tipo' varchar(50) NOT NULL DEFAULT '',
'ObsTipo' varchar(50) NOT NULL DEFAULT '',
'CodProd' varchar(20) NOT NULL DEFAULT '',
'Prod' varchar(50) NOT NULL DEFAULT '',
'referencia' varchar(50) NOT NULL DEFAULT '',
'ValUniProd' varchar(15) NOT NULL DEFAULT '',
'UniProd' varchar(5) NOT NULL DEFAULT '',
'QuantidadeProd' varchar(10) NOT NULL DEFAULT '',
'ValorProd' varchar(20) NOT NULL DEFAULT '',
'Maquina' varchar(50) NOT NULL DEFAULT '',
'Cod_Cliente' varchar(50) NOT NULL DEFAULT '',
'Cliente' varchar(250) NOT NULL DEFAULT '',
'Data' date DEFAULT NULL,
'Mes' varchar(45) NOT NULL DEFAULT '',
'Ano' varchar(4) NOT NULL DEFAULT '',
'Cod_vendedor' varchar(15) NOT NULL DEFAULT '',
'Nome_Vendedor' varchar(155) NOT NULL DEFAULT '',
PRIMARY KEY ('Cod')
Payment Form
'cod' varchar(20) NOT NULL DEFAULT '',
'descricao' varchar(255) NOT NULL DEFAULT '',
Sql I tried, 20% of records returned with wrong data compared to equal or different
SQL = "SELECT *,
IF(venda.cod = vendaesc.Venda and venda.forma_pagamento > 1,'IGUAL','DIFERENTE') AS resultado_agrupa,
venda.TotalS AS total_venda_agrupa,
venda_forma_pagamento.descricao AS nome_forma_pagamento,
vendaesc.QUANTIDADEprod as qtd,
(vendaesc.QUANTIDADEprod * vendaesc.ValUniProd) As total_soma
FROM vendaesc,venda,venda_forma_pagamento
where vendaesc.data='" & DateRat & "' AND
venda.cod = vendaesc.venda AND venda.forma_pagamento =
venda_forma_pagamento.cod order by venda.cod"
Programming is VB6: (
SQL: