Click to See Complete Forum and Search --> : sql2kQuery


ikcha
November 4th, 2007, 07:48 PM
got a text file with list of players. what would be query based on the list to obtain age of each player and total number of games each has played?. How if list size vary?.
NameA
NameB
NameC
etc.

ikcha
November 7th, 2007, 12:09 PM
got a table1 as
player#, game#, miunte, country, score
i like to sum scores for each player to come up
with a table2:
player#, game#, country, totalscores
my query:
select T.player, T.game, T.country,sum(T.score)
from table1 as T, table1 as S where T.player# <> S.player# and T.game# <> S.game#
group by T.player#, S.game#, S.country
order by T.player# asc
my total score doesn't come up right.

KrisSimonis
November 8th, 2007, 05:27 AM
Could you clarify a bit more precisely how your table is
structured and what you want? Its not entirely clear to me.
From what I understand, you have a table which
contains every player's number, a number identifieing
a unique game he played, and his score in that game,
and you want a total of all the games he's played.
If that is the case, it's quite easy:

Table ScoresPerGame
Player#
Game#
Score

SELECT Player, SUM(Score)
FROM ScoresPerGame
GROUP BY Game

ikcha
November 8th, 2007, 10:01 AM
yes.
plyer# game# location colB score
1 game1 CountryA 1 1
1 game1 CountryB 1 1
2 game2 CountryD 2 1
2 game2 CountryH 2 2query should get this result from table above.
player# game# colB totalscore
1 game1 1 2
2 game2 2 3

KrisSimonis
November 8th, 2007, 10:31 AM
Ahh ok, now it's clear.

This is what you want:

SELECT Player, Game, ColB, SUM(Score)
FROM Table1
GROUP BY Player, Game, ColB

This will sum together all points a player earned in a game
for every country he's played.