Skip to content

Instantly share code, notes, and snippets.

@cesarAugusto1994
Created May 9, 2016 16:59
Show Gist options
  • Save cesarAugusto1994/a7196f3714a0e07f5e9966f25ad82023 to your computer and use it in GitHub Desktop.
Save cesarAugusto1994/a7196f3714a0e07f5e9966f25ad82023 to your computer and use it in GitHub Desktop.
SELECT xalog2.storeno, xalog2.pdvno, xalog2.xano, xalog2.date,
SUM(xalog2.qtty/1000 * xalog2.price) AS valor_total,
xalog2.xatype,
IF(xalog2.qtty <0, 1, 0) AS troca_devolucao,
paym.name AS metodo_pagamento,
IF(xalog2.price > 0, 'Venda',
IF(xalog2.price < 0 AND xalog2.xatype = 11, 'Devolução', 'Troca')
) as tipo_transacao, p.id_pessoa, p.nome_pessoa, p.ddd_telefone, p.telefone
FROM sqldados.xalog2
LEFT JOIN sqldados.paym
ON (xalog2.payno = paym.no)
LEFT JOIN webpdv.pessoas p
ON xalog2.custno = p.custno
WHERE p.id_pessoa = 1358591
AND xalog2.date between 20160301 AND 20160430
GROUP BY xalog2.storeno, xalog2.pdvno, xalog2.xano
ORDER BY xalog2.date;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment