Jump to content

GROUP BY error


ninedoors

Recommended Posts

I am using this query to pull out stats for a hockey league but I am getting an Invalid use of group by function error.  I assume it is something simple that I am missing:

 

SELECT t.team_id, t.alt_name, t.career_id, d.division, t.logo, 
SUM(IF(gg.outcome LIKE 'w%', 1, 0)) as w, 
SUM(IF(gg.outcome LIKE 'l%', 1, 0)) as l,
SUM(IF(gg.outcome = 't', 1, 0)) as t, 
SUM(SUM(IF(gg.outcome LIKE 'w%', 1, 0))*2 + SUM(IF(gg.outcome = 't', 1, 0))) as pts 
FROM smf_osm_teams as t 
LEFT JOIN smf_osm_goalie_games as gg ON(t.team_id = gg.team_id) 
LEFT JOIN smf_osm_schedule as sc ON(gg.game_id = sc.game_id) 
LEFT JOIN smf_osm_divisions as d ON(t.division = d.division_id) 
WHERE t.division > 0 AND t.event_id = 3 AND sc.reg_play = 'r' AND d.division = 'A' GROUP BY t.team_id, t.alt_name, t.career_id, t.logo ORDER BY pts ASC, gp ASC, w DESC

 

Thanks for the help

Link to comment
https://forums.phpfreaks.com/topic/196621-group-by-error/
Share on other sites

Out of curiosity what does this query return?

 

SELECT t1.team_id, t1.alt_name, t1.career_id, t4.division, t4.logo,
SUM(IF(t2.outcome LIKE 'w%', 1, 0)) as w,
SUM(IF(t2.outcome LIKE 'l%', 1, 0)) as l,
SUM(IF(t2.outcome = 't', 1, 0)) as t,
SUM(SUM(IF(gg.outcome LIKE 'w%', 1, 0))*2 + SUM(IF(gg.outcome = 't', 1, 0))) as pts
FROM smf_osm_teams t1
LEFT JOIN smf_osm_goalie_games t2 ON(t1.team_id = t2.team_id)
LEFT JOIN smf_osm_schedule t3 ON(t2.game_id = t3.game_id)
LEFT JOIN smf_osm_divisions t4 ON(t1.division = t4.division_id)
WHERE t1.division > 0 
AND t1.event_id = 3 
AND t3.reg_play = 'r' 
AND t4.division = 'A' 
GROUP BY t1.team_id, t1.alt_name, t1.career_id, t4.division, t1.logo 

 

Link to comment
https://forums.phpfreaks.com/topic/196621-group-by-error/#findComment-1032594
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.