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 |
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2003-06-28 : 09:02:15
|
I have a tbl_statistiekenWith:id id_game id_player score313 32 23 60313 32 23 26313 32 23 140313 32 23 33 Now I want the average score of player 23.Thats not so difficult but again a dart question The score 60/3 = 20 average (divided thrue 3 because I trow 3 darts)26/3 = 8.66140/3 = 46.6633/3 = 11Total = 20 + 8.66 + 46.66 + 11 = 86.32 / 4(amount of record) = 21.58You can also say 60 + 26 + 140 + 33 = 259 / 12 ( 4 record * 3 darts) = 21.58So That is the value I want because the player trowd 21.58 point a dart. I hope I am clear enough this time. Thanxx For the helpCyaBjornCyaBjorn |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-06-28 : 09:34:19
|
| id id_game id_player score313 32 23 60313 32 23 26313 32 23 140313 32 23 33select id, id_game, id_player, avg(score/3.0) as AvgPerDartfrom tbl_statistiekengroup by id, id_game, id_player- Jeff |
 |
|
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2003-06-28 : 09:47:33
|
Oke this is allready a start but I get the average of every single row now. And I want the avarage of every row together.Hope you know the solution to this one!ThanxxBjorn |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2003-06-28 : 10:04:45
|
| select id_player, avg(score/3.0) as AvgPerDart from tbl_statistieken group by id_player |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-06-28 : 10:06:54
|
| Run the query and look at the results. it doesn't give the average for each row, just for each player. unless your sample data is not accurate.i.e., if each row in your data doesn't have the same value in "ID" column (in your example, "313"), then exlcude that column from the SELECT and the GROUP BY:select id_game, id_player, avg(score/3.0) as AvgPerDart from tbl_statistieken group by id_game, id_player you can also get the average for each game, all players:select id_game, avg(score/3.0) as AvgPerDart from tbl_statistieken group by id_gameand you can also get the average for each player, for all games:select id_player, avg(score/3.0) as AvgPerDart from tbl_statistieken group by id_playerread more about GROUP BY and aggregate functions in books on-line.- JeffEdited by - jsmith8858 on 06/28/2003 10:07:43 |
 |
|
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2003-06-28 : 10:25:00
|
Great!!!Yes I made a copy/past error:id id_game id_player score313 32 23 60314 32 26 26315 32 23 140316 32 26 33317 32 23 11318 32 26 4319 32 23 10320 32 26 100321 33 44 50322 33 48 150323 33 44 71324 33 48 56 So I also have to add where id_game = [id_game_field] And id_player = [id_player_field].Only one small question I dont want to view:33,336333333But33,34ThanxxBjorn |
 |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2003-06-28 : 11:57:50
|
| Check for Round function in BOL.-------------------------What lies behind you and what lies ahead of you are small matters compared to what lies within you.-Ralph Waldo Emerson |
 |
|
|
|
|
|
|
|