CONSULTA SQL
Olá amigos do VBMania!
Estou precisando fazer uma consulta SQL e preciso da ajuda de vcs.
Minha Tabela SL1010.
Campos: L1_FILIAL (Filial), L1_EMISNF(Campo Data), L1_VLRLIQ(Valor) e L1_FORMPG(Forma de Pagamento)
Então fica assim:
02 - 16.05.2012 - R$ 1.000,00 - CC (Cartão de Crédito)
02 - 16.05.2012 - R$ 3.000,00 - CC (Cartão de Crédito)
02 - 16.05.2012 - R$ 1.500,00 - CH (Cheque)
02 - 16.05.2012 - R$ 900,00 - CH (Cheque)
03 - 16.05.2012 - R$ 500,00 - CD (Cartão de Débito)
04 - 16.05.2012 - R$ 2.000,00 - R$ (Dinheiro)
Usando na SQL o comando COUNT e SUM.
Quero pegar o total de cartão de crédito por perÃodo e Filial
Exemplo:
LOJA - DATA VALOR TIPO
02 16.05.2012 R$ 4.000,00 CC
02 16.05.2012 R$ 2.400,00 CH
03 16.05.2012 R$ 500,00 CD
Agradeço pela ajuda!
Estou precisando fazer uma consulta SQL e preciso da ajuda de vcs.
Minha Tabela SL1010.
Campos: L1_FILIAL (Filial), L1_EMISNF(Campo Data), L1_VLRLIQ(Valor) e L1_FORMPG(Forma de Pagamento)
Então fica assim:
02 - 16.05.2012 - R$ 1.000,00 - CC (Cartão de Crédito)
02 - 16.05.2012 - R$ 3.000,00 - CC (Cartão de Crédito)
02 - 16.05.2012 - R$ 1.500,00 - CH (Cheque)
02 - 16.05.2012 - R$ 900,00 - CH (Cheque)
03 - 16.05.2012 - R$ 500,00 - CD (Cartão de Débito)
04 - 16.05.2012 - R$ 2.000,00 - R$ (Dinheiro)
Usando na SQL o comando COUNT e SUM.
Quero pegar o total de cartão de crédito por perÃodo e Filial
Exemplo:
LOJA - DATA VALOR TIPO
02 16.05.2012 R$ 4.000,00 CC
02 16.05.2012 R$ 2.400,00 CH
03 16.05.2012 R$ 500,00 CD
Agradeço pela ajuda!
Ex. Sum:
select L1_Filial,L1_EmisNF,L1_FormPG,sum(l1_vllrliq) as vltotal from Sl1010
group by L1_Filial,L1_EmisNF,L1_FormPG
Ex. Count:
select L1_Filial,L1_EmisNF,L1_FormPG,count(*) as qtTotal from Sl1010
group by L1_Filial,L1_EmisNF,L1_FormPG
select L1_Filial,L1_EmisNF,L1_FormPG,sum(l1_vllrliq) as vltotal from Sl1010
group by L1_Filial,L1_EmisNF,L1_FormPG
Ex. Count:
select L1_Filial,L1_EmisNF,L1_FormPG,count(*) as qtTotal from Sl1010
group by L1_Filial,L1_EmisNF,L1_FormPG
JCARLOS, Eu consegui da seguinte forma:
SELECT v.L1_FILIAL AS LOJA, L1_EMISNF AS DATA,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]CC[ô]) Cartao,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]CH[ô]) Cheque,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]R$[ô]) Diqueiro,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]CD[ô]) Debito,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]FO[ô]) Folha,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]SR[ô]) Saldo,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]FI[ô]) Crediario,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL) Total
FROM SL1010 v
WHERE
L1_EMISNF=[ô]20120516[ô]
GROUP BY L1_FILIAL, L1_EMISNF
Fico agradecido pela atenção e para quem precisar, fica aà a dica.
SELECT v.L1_FILIAL AS LOJA, L1_EMISNF AS DATA,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]CC[ô]) Cartao,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]CH[ô]) Cheque,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]R$[ô]) Diqueiro,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]CD[ô]) Debito,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]FO[ô]) Folha,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]SR[ô]) Saldo,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL AND c.L1_FORMPG=[ô]FI[ô]) Crediario,
(SELECT SUM(c.L1_VLRLIQ) FROM SL1010 c WHERE c.l1_emisnf=v.l1_emisnf AND c.L1_FILIAL=v.L1_FILIAL) Total
FROM SL1010 v
WHERE
L1_EMISNF=[ô]20120516[ô]
GROUP BY L1_FILIAL, L1_EMISNF
Fico agradecido pela atenção e para quem precisar, fica aà a dica.
Tópico encerrado , respostas não são mais permitidas