Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.