SQL Server 按连续列分组问题
我尝试使用 concat
列对查询结果进行分组,但我坚持这样做。
所以这是我的查询:
SELECT
CONCAT (a.athleteLastName, ', ', a.athleteFirstName, ' (', a.athletePosition, ')') AS "Athlete",
COUNT(M.awardName) AS "Number of Awards Won"
FROM
award m
FULL OUTER JOIN
winner w ON m.awardId = w.awardId
FULL OUTER JOIN
athlete a ON w.athleteId = a.athleteId
GROUP BY
M.awardId, athleteLastName, a.athleteFirstName,a.athletePosition
ORDER BY
M.awardId DESC, Athlete;
这是结果:
Trout, Mike (OF) 1
Arenado, Nolan (3B) 4
Arenado, Nolan (3B) 7
Trout, Mike (OF) 3
但我想按玩家对奖励计数进行分组,它应该像这样结束:
Arenado, Nolan (3B) 13
Trout, Mike (OF) 4
I am trying to group by the results of the query with a concat
column, but I am stuck with it.
So this is my query:
SELECT
CONCAT (a.athleteLastName, ', ', a.athleteFirstName, ' (', a.athletePosition, ')') AS "Athlete",
COUNT(M.awardName) AS "Number of Awards Won"
FROM
award m
FULL OUTER JOIN
winner w ON m.awardId = w.awardId
FULL OUTER JOIN
athlete a ON w.athleteId = a.athleteId
GROUP BY
M.awardId, athleteLastName, a.athleteFirstName,a.athletePosition
ORDER BY
M.awardId DESC, Athlete;
This is the result:
Trout, Mike (OF) 1
Arenado, Nolan (3B) 4
Arenado, Nolan (3B) 7
Trout, Mike (OF) 3
But I want to group the count of awards by the player, and it should end like this:
Arenado, Nolan (3B) 13
Trout, Mike (OF) 4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Arenado、Nolan (3B)
如何成为13
?如果只是简单地总结奖项,您可以使用子查询,可以尝试以下操作:How can
Arenado, Nolan (3B)
becomes13
? If simply summing up the awards, you can use subquery and can try this: