Fórum favor - preciso de um SQL que acumule o total das vendas #324139
23/06/2006
0
Ja fiz varias tentativas, mas nao estou conseguindo acumular os valores.
Ja tentei todos estes SQL
SELECT DISTINCT IDCLIENTE,
SUM(total) FROM VENDAS group by IDCLIENTE, NRVENDA HAVING DATA>=´01/01/2006´ AND DATA<=´01/31/2006´
SELECT IDCLIENTE,
SUM(total) FROM VENDAS group by IDCLIENTE, NRVENDA HAVING DATA>=´01/01/2006´ AND DATA<=´01/31/2006´
Só que nao estou conseguindo acumular os valores, me ajudem!!
Frostlost
Curtir tópico
+ 0Posts
23/06/2006
Eliasexner
Tente esta instrução SQL:
SELECT IDCLIENTE, SUM(total) FROM VENDAS
where DATA>=´01/01/2006´ AND DATA<=´01/31/2006´
group by IDCLIENTE
Se vc incluir o campo ´ NRVENDA ´ no group by, vc vai agrupar as vendas por registro de venda, ou seja, vai ter o valor de cada venda separada.
Espero ter ajudado
Gostei + 0
23/06/2006
Bruno_hanukah
SELECT
SUM(total)
FROM
VENDAS
WHERE ID_CLIENTE = 1
HAVING
DATA>=´01/01/2006´ AND DATA<=´01/31/2006´
Gostei + 0
23/06/2006
Emrinfo
Segue a instrucao SQL:
select distinct IDCLIENTE, coalesce (sum(Total), 0) as Tot_Vendas from Vendas where (DATA between :Dt_ini and :Dt_fim ) group by IDCLIENTE order by 1
ou voce pode acumular pelo NOME_CLIENTE:
select distinct IDCLIENTE, CL.NOME_CLI, coalesce (sum(Total), 0) as Tot_Vendas from Vendas left join CLIENTES CL ON IDCLIENTE = ID_CODIGO_CLI where (DATA between :Dt_ini and :Dt_fim ) group by CL.NOME_CLI order by 2, 1
Espero ter ajudado.
Evaldo.
Gostei + 0
24/06/2006
Frostlost
select distinct IDCLIENTE, sum(Total) from Vendas where (DATA >=´01/01/2006´ and DATA<=´01/31/2006´ ) group by IDCLIENTE order by 1
Obrigado!!!
Claudio
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)