favor - preciso de um SQL que acumule o total das vendas
favor - preciso de um SQL que acumule o total das vendas de clientes dentro de um determinado periodo;
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!!
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
Curtidas 0
Respostas
Eliasexner
23/06/2006
olá Amigo.
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
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
Bruno_hanukah
23/06/2006
Experimenta fazer o seguinte
SELECT
SUM(total)
FROM
VENDAS
WHERE ID_CLIENTE = 1
HAVING
DATA>=´01/01/2006´ AND DATA<=´01/31/2006´
SELECT
SUM(total)
FROM
VENDAS
WHERE ID_CLIENTE = 1
HAVING
DATA>=´01/01/2006´ AND DATA<=´01/31/2006´
GOSTEI 0
Emrinfo
23/06/2006
Boa Noite,
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.
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
Frostlost
23/06/2006
Obrigado a todos que colaboraram, segue abaixo o codigo que usei baseado no exemplo dos colegas acima para futura referencia das pessoas que utilizam o forum.
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
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