我试图从我在下面的图片
中获得的结果中获取PlayerID
我用来显示的查询是:
SELECT PlayerIDFK, sum(TwoPointMade) as TwoPointMade, sum(ThreePointMade) as ThreePointMAde
FROM PlayerPerformance GROUP BY PlayerIDFK;
我还有另一个查询返回这个案例中两列总和的最大值47,这是正确的答案,但我也想获得PlayerIDFK。
SELECT MAX(SUM(TwoPointMade) + SUM(ThreePointMade)) AS "Points"
FROM PlayerPerformance GROUP BY PlayerIDFK;
当我尝试使用查询获取玩家ID时,我得不到单组组功能。这是我试图使用的查询:
SELECT PlayerIDFK, MAX(SUM(TwoPointMade) + SUM(ThreePointMade)) AS "Points"
FROM PlayerPerformance GROUP BY PlayerIDFK;
答案 0 :(得分:0)
使用order by
和rownum
(或12c +中的fetch first 1 row only
):
SELECT *
FROM (SELECT PlayerIDFK, sum(TwoPointMade) as TwoPointMade, sum(ThreePointMade) as ThreePointMAde
FROM PlayerPerformance
GROUP BY PlayerIDFK
ORDER BY ( sum(TwoPointMade) + sum(ThreePointMade) ) desc
) pp
WHERE rownum = 1;