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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 I NEED TO DIVIDE MY SUM AND COUNT HOW???

Author  Topic 

SAMHOR
Starting Member

1 Post

Posted - 2012-04-30 : 13:25:56
Hello All,

I need to divide my sum by my count.
I've so far got this

SELECT SUM (PLAYERTOTALSCORE), COUNT(playertotalscore)FROM GAME_PLAYER;

Everytime i try to use / for divide it breaks :(

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-04-30 : 13:57:48
What do you mean, "breaks"?

Actual error?
No error, no data?









How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

vijays3
Constraint Violating Yak Guru

354 Posts

Posted - 2012-04-30 : 14:07:52
[code]Please provide sample data desired output .so that we can try to provide you solution [/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-30 : 14:25:13
Whats the cause of breakage? is it divide by 0?
if yes, below should sort it out

SELECT SUM (PLAYERTOTALSCORE)/NULLIF(COUNT(playertotalscore),0)
FROM GAME_PLAYER


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

vinu.vijayan
Posting Yak Master

227 Posts

Posted - 2012-05-01 : 07:57:10
Yes, Visakh's query should work fine.

N 28° 33' 11.93148"
E 77° 14' 33.66384"
Go to Top of Page
   

- Advertisement -