MySQL,使用子查询获取分数排名
我试图找出这位特定球员在 NBA 得分后卫中的排名。我使用 stackoverflow 上的这篇文章作为指南。
我收到错误“组功能使用无效”。
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的子查询是错误的,你不能在没有
GROUP BY
和WHERE
中使用SUM
,所以你必须使用HAVING
。我让你检查: http://dev.mysql.com/doc/ refman/5.0/fr/select.html
Your subquery is wrong, you cannot use
SUM
withoutGROUP BY
and inWHERE
, so you have to useHAVING
.I let you check : http://dev.mysql.com/doc/refman/5.0/fr/select.html