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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 For...Each...

Author  Topic 

davidshq
Posting Yak Master

119 Posts

Posted - 2005-12-03 : 00:14:07
I have two tables. The first one is a game table, the second is a rating table. In the first one are descriptions of group games, in the second, different user's ratings of those games.
I need to do something like (pseudo-code):
For Each GameID in Ratings
Add GameID Values Together
Divide By Number of Values
Insert Resulting Average into OverallPopularity
Any ideas? Pointers to website that might help me discover how to code this?
David.

- http://www.gamesecretary.com/
- http://www.thehungersite.com/
- http://www.grid.org/

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2005-12-03 : 00:31:14
Use the AVG function:

SELECT GameID, AVG(values) FROM Ratings GROUP BY GameID
Go to Top of Page

davidshq
Posting Yak Master

119 Posts

Posted - 2005-12-03 : 10:23:40
The values are in the table. How do I get them into the (values)?
e.g. Table data:
John - Kickball - 10
Mary - Kickball - 5
Adam - Kickball - 8
SELECT GameID, AVG(John, Mary, Adam) FROM Ratings GROUP by Game ID
David.

- http://www.gamesecretary.com/
- http://www.thehungersite.com/
- http://www.grid.org/
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2005-12-03 : 13:40:12
Have you bothered to look up AVG and other aggregate functions in Books Online to see how they work? Your syntax isn't even correct.
Go to Top of Page

davidshq
Posting Yak Master

119 Posts

Posted - 2005-12-03 : 13:51:17
Someone helped me solve this problem in this thread:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=58545
David.

- http://www.gamesecretary.com/
- http://www.thehungersite.com/
- http://www.grid.org/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-05 : 00:33:13
If you provided some sample data and the result you want then you would have got correct query so that you might avoid opening other thread

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -