tags:

views:

36

answers:

1

I am trying to find out where this particular player ranks among shooting guards in the NBA. I am using this post on stackoverflow for a guide.

I get the error "Invalid use of group function".

  SELECT
  first,
  last,
  team,
  pos,
  SUM(points) AS scoresum,
  ROUND(AVG(points), 2) AS avgpoints,
  (SELECT
     COUNT(*)
   FROM nbaboxscore AS bpnb
   WHERE (bpnb.first, bpnb.last, SUM(bpnb.points)) >= (bpn.first, bpn.last, SUM(bpn.points))) AS rank
FROM nbaboxscore AS bpn
WHERE bpn.pos = 'SG'
    AND bpn.date >= '2009-10-01'
    AND FIRST = 'Joe'
    AND LAST = 'Johnson'
GROUP BY bpn.first, bpn.last, bpn.team
ORDER BY scoresum DESC

I'm not exactly sure if it's possible this way?

+1  A: 

Your subquery is wrong, you cannot use SUM without GROUP BY and in WHERE, so you have to use HAVING. I let you check : http://dev.mysql.com/doc/refman/5.0/fr/select.html

MatTheCat