ninedoors Posted March 26, 2010 Share Posted March 26, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/196621-group-by-error/ Share on other sites More sharing options...
fenway Posted March 26, 2010 Share Posted March 26, 2010 Drop the group by and the sums, and bring them back one at a time. Quote Link to comment https://forums.phpfreaks.com/topic/196621-group-by-error/#findComment-1032368 Share on other sites More sharing options...
ninedoors Posted March 26, 2010 Author Share Posted March 26, 2010 Ok, but what if I want it all in one query is there somehting I can change that to do it all in one query? Quote Link to comment https://forums.phpfreaks.com/topic/196621-group-by-error/#findComment-1032427 Share on other sites More sharing options...
JustLikeIcarus Posted March 27, 2010 Share Posted March 27, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/196621-group-by-error/#findComment-1032594 Share on other sites More sharing options...
ninedoors Posted March 27, 2010 Author Share Posted March 27, 2010 I figured it out. I had a SUM instead another SUM which of course is not allowed. This query returns the totals for each team in my hockey league likw wins, losses, ties, pts, golas for, golas against. Quote Link to comment https://forums.phpfreaks.com/topic/196621-group-by-error/#findComment-1032700 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.