Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
monaya
Yak Posting Veteran
58 Posts |
Posted - 2009-05-26 : 19:17:05
|
| I'm just trying to gather an average rating.I want the sum of all x columns and then I want to divide by the count of x columns for the average of x column, but how do i get the SUM and the count in the same table? Thanks |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-05-26 : 19:42:12
|
| Why not just use the AVG() function?SELECT SUM(x)/COUNT(x) FROM YourTable will return the same results asSELECT AVG(x) FROM YourTableSome days you're the dog, and some days you're the fire hydrant. |
 |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-05-26 : 19:47:45
|
| BTW if you want precision with your result then do something likeSELECT AVG(x*1.0) FROM YourTableSome days you're the dog, and some days you're the fire hydrant. |
 |
|
|
monaya
Yak Posting Veteran
58 Posts |
Posted - 2009-05-30 : 02:11:13
|
| Thanks, Sorry for the late reply I didnt get an email about this until today even though I was subscribed to the topic.I'll try that tomorrow! |
 |
|
|
|
|
|