I think it might help with future questions with a similar situation:
Assuming the following data source
datavenda vendedor valor
2015-04-01 FULANO1 700,00
2015-04-02 FULANO1 300,00
2015-04-01 FULANO2 600,00
2015-04-02 FULANO2 200,00
2015-04-01 FULANO3 400,00
2015-04-02 FULANO3 300,00
2015-04-01 FULANO4 30,00
2015-04-02 FULANO4 70,00
2015-04-01 FULANO1 1500,00
2015-04-01 FULANO1 350,00
2015-04-02 FULANO1 750,00
2015-04-02 FULANO1 300,00
2015-04-01 FULANO2 1800,00
2015-04-01 FULANO3 600,00
2015-04-01 FULANO4 800,00
2015-04-03 FULANO1 1500,00
2015-04-03 FULANO2 3000,00
2015-04-04 FULANO4 6000,00
The query below brings the total of each seller between a start date and an end date.
declare @dt_inicio date
declare @dt_fim date
set @dt_inicio = '2015-04-01'
set @dt_fim = '2015-04-04'
SELECT distinct @dt_inicio as [inicio],
@dt_fim as [fim],
A.vendedor, soma.v as [TOTAL]
from VENDAS AS A
cross apply (
select sum(valor) v from VENDAS
where datavenda between @dt_inicio and @dt_fim
and vendedor = A.vendedor
) soma
where datavenda between @dt_inicio and @dt_fim
order by soma.v DESC
Result:
2015-04-01 2015-04-04 FULANO4 6900,00
2015-04-01 2015-04-04 FULANO2 5600,00
2015-04-01 2015-04-04 FULANO1 5400,00
2015-04-01 2015-04-04 FULANO3 1300,00
To increase, we can add the corresponding percentage to each salesperson within the search period.
SELECT distinct @dt_inicio as [inicio],
@dt_fim as [fim],
A.vendedor, soma.v as [TOTAL],
format((soma.v / soma2.v), 'p') as [% sobre TOTAL NO PERÍODO]
from VENDAS AS A
cross apply (
select sum(valor) v from VENDAS
where datavenda between @dt_inicio and @dt_fim
and vendedor = A.vendedor
) soma
cross apply (
select sum(valor) v from VENDAS
where datavenda between @dt_inicio and @dt_fim
) soma2
where datavenda between @dt_inicio and @dt_fim
order by soma.v DESC
Result:
2015-04-01 2015-04-04 FULANO4 6900,00 35,93%
2015-04-01 2015-04-04 FULANO2 5600,00 29,16%
2015-04-01 2015-04-04 FULANO1 5400,00 28,12%
2015-04-01 2015-04-04 FULANO3 1300,00 6,77%
I have a habit of always keeping dates in the American format. To format for Brazil just use:
...
format(@dt_inicio, 'dd/MM/yyyy')as [inicio],
format(@dt_fim, 'dd/MM/yyyy')as [fim], ...
If you prefer, you do not have to leave the dates @dt_inicio as [inicio], @dt_fim as [fim]
in the select. You can withdraw to return only the name and total of each seller on the lines.