bernie
bernie

Reputation: 1

calculate the average cost

How do I get the average cost per visit in a TSQL statement?

I have the total count of visits and summed the cost.

Upvotes: 0

Views: 761

Answers (3)

Andomar
Andomar

Reputation: 238176

If you have the total count and summed cost, the average is just a division away:

 summed cost
------------- = average cost
 total count

Upvotes: 0

Mark SQLDev
Mark SQLDev

Reputation: 539

Can't you simply divide the number of visits by the total cost? (I.e., SUM(Cost) / SUM(Count))

Upvotes: 0

Ian Henry
Ian Henry

Reputation: 22403

You can use the AVG aggregate function:

http://msdn.microsoft.com/en-us/library/ms177677.aspx

Upvotes: 2

Related Questions