Forum Moderators: coopster

Message Too Old, No Replies

last occurrence while using GROUP BY

         

mooger35

3:17 pm on May 8, 2006 (gmt 0)

10+ Year Member



what I have is a player stats page. It is set up like this:

statid ¦ gameid ¦ playerid ¦ teamname ¦ blah blah blah

I use group by to pull all the stats for each playerid. But what I find is that when a player changes teams it pulls the first teamname from the table rather than the last. Will MAX(teamname) work to show the final team or will that just alphabetize it?

mooger35

4:59 pm on May 8, 2006 (gmt 0)

10+ Year Member



Here is my query:

$query_goalies = "SELECT goalie_stats.playerid, goalie_stats.teamid, firstname, lastname, teamname,
SUM(IF(time='0',1,0)) AS gp,
SUM(IF(time='0',mins,0)) AS mins,
SUM(IF(result='win' AND time='0',1,0)) AS wins,
SUM(IF(result='loss' AND time='0',1,0)) AS losses,
SUM(IF(result='tie' AND time='0',1,0)) AS ties,
SUM(IF(time='0',ga,0)) AS ga,
SUM(IF(ga='0' AND time='0' AND result!='NULL',1,0)) AS so,
SUM(IF(time='0',ga,0))/SUM(IF(time='0',mins,0))*40 AS gaa,
SUM(IF(time='1',1,0)) AS pogp,
SUM(IF(time='1',mins,0)) AS pomins,
SUM(IF(result='win' AND time='1',1,0)) AS powins,
SUM(IF(result='loss' AND time='1',1,0)) AS polosses,
SUM(IF(result='tie' AND time='1',1,0)) AS poties,
SUM(IF(time='1',ga,0)) AS poga,
SUM(IF(ga='0' AND time='1' AND result!='NULL',1,0)) AS poso,
SUM(IF(time='1',ga,0))/SUM(IF(time='1',mins,0))*40 AS pogaa
FROM players, goalie_stats, teams
WHERE teams.teamid = goalie_stats.teamid AND players.playerid = goalie_stats.playerid AND season = 2006
GROUP BY goalie_stats.playerid
ORDER BY gaa ASC, mins DESC";

I tried to add LAST() in but I get an error:

coopster

1:43 pm on May 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It's the "Single-Value Rule". Perhaps this thread and associated links will help ...

[webmasterworld.com...]

mooger35

4:23 pm on May 9, 2006 (gmt 0)

10+ Year Member



I found a work around using a seperate query...

Thanks for the help