how to calculate percent of total within group by statement?

Viewed 18422

I have a table with 1 record per sale per salesperson per day

NAME  DATE
joe   1-1-13
joe   1-1-13
joe   1-1-13
dave  1-1-13
joe   1-2-13

I used this to create & populate the table

create table #sales (name varchar(10), salesdate date )
insert into #sales (name, salesdate) 
values ('joe', '01-01-2013'), ('joe','01-01-2013'), 
       ('joe', '01-01-2013'), ('dave','01-01-2013'),  
         ('joe','01-02-2013')

I want a query to pull up the percent of each salesperson's sales by day

(for example on 1-1-13 Joe sold 3 units out of 4 total for the day (75%) but I dont know how the SQL can pull up the daily total of all sales for the day regardless of salesperson

This is as close as I got.

select name, salesdate, count(*) as "dailyTotal"
from #sales
group by name, salesdate

How can I include the daily total that is so that it can be used in calculating percent total for the day?

4 Answers
Related