MySQL Forums
Forum List  »  Portuguese

Select Condicional
Posted by: Maciel Ferreira
Date: July 08, 2017 01:50PM

Olá a todos.

Tenho uma questão da qual gostaria de ajuda.
Tenho um relatorio de um sistema que me da o seguinte resultado após inserir uma data inicial e final.

id | Tipo Pagamento | Total
1 Dinheiro 100
2 Debito 230
3 Credito 300

Tranquilo até aqui.

O que eu quero é fazer um select que me mostre exatamente estes valores e desta forma ai apresentada.
select sum(i.Total) total // esse é o valor total obviamente
from documentsheaders d // essa tabela é de onde somo mas..
inner join invoicepaymentdetails i on d.Number = i.InvoiceNumber // essas duas tabelas são importantes pois as informações precisam ser unicas.
inner join xconfigpaymenttypes p on d.PaymentType= p.Id // aqui é onde ficam as descrições das formas de recebimento
where d.closedate between '2017-06-23 00:00:01' and '2017-06-23 23:59:59'
and i.PaymentTypeId=1 // tipo de recebimento

Se eu fizer essa consulta ai vai dar certo, o que gostaria era de chamar o resultado para os três valores como no relatorio. Mas se colocar por exemplo o código ai em baixo já não funciona mais, ele me traz valores incorretos. Talvez usar um case ou for, mas não sei mesmo como conseguiria.


select UPPER(p.Description) as Description,sum(i.Total) total
from documentsheaders d
inner join invoicepaymentdetails i on d.Number = i.InvoiceNumber
inner join xconfigpaymenttypes p on d.PaymentType= p.Id
where d.closedate between '2016-01-01 00:00:01' and '2017-01-31 23:59:59' and i.PaymentTypeId not in (1)
group by p.Description;

Options: ReplyQuote


Subject
Views
Written By
Posted
Select Condicional
974
July 08, 2017 01:50PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.