troubleshooting Question

Calculating percentages in SQL

Avatar of r270ba
r270ba asked on
Microsoft SQL ServerMicrosoft SQL Server 2005SQL
2 Comments1 Solution819 ViewsLast Modified:
Ok I have a sql statement that returns 3 columns:

Salesperson, Customer they met with, number of times they have met with that customer

select owneridname, regardingobjectidname, count(*) as hits from appointment
where statecode = '1'
group by owneridname, regardingobjectidname
order by hits desc

What I am wanting to do...I want to be able to take the total number of "hits" for an appointment (the second column) and divide it by the total number of hits that are returned for the salesperson (regardless of customer).  

This will allow me to see if someone is seeing a customer too much and neglecting other customers.

Below is a copy of a few results from the query above.  I want to add a % column and divide hits by the sum() of all hits for that username
OnweridName       Customer                  # of completed appointments
Phillip Crisp	SPRING LAKE COUNTRY CLUB	21
Ivey Barber	LINVILLE GOLF CLUB	18
Nick Willis	RESERVE AT LAKE KEOWEE	17
Phillip Crisp	QUAIL HOLLOW CC	15
Nick Willis	HOLLY TREE COUNTRY CLUB	14
Nick Willis	THORNBLADE CLUB INC.	13
Robert Hinton	WILLOWHAVEN COUNTRY CLUB	12
Phillip Crisp	LONGLEAF GOLF & COUNTRY CLUB	12
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros