我有一个游戏分数数据集,如下所示。我正在尝试使用类似的东西计算新的三列条件:
数据集:
Player Player_Rank Score_Game1 Score_Game2 Score_Game3
Tom 1 87 84 92
John 2 91 84 87
Peter 3 81 83 83
Hank 4 85 72 57
Alfred 5 60 58 54
Mike 6 79 74 64
Joe 7 49 81 62
Marc 8 70 87 47
Sean 9 73 51 69
新列计算Oracle SQL代码:
case when Player_Rank <= 3 then Score_Game1 else . end as Score_Game1_r;
case when Player_Rank <= 3 then Score_Game2 else . end as Score_Game2_r;
case when Player_Rank <= 3 then Score_Game3 else . end as Score_Game3_r;
有没有办法让我只做一个case语句,如下所示而不是为所有列重复它?
case when Player_Rank <= 3 then
Score_Game1 else . end as Score_Game1_r;
Score_Game2 else . end as Score_Game2_r;
Score_Game3 else . end as Score_Game3_r;
最终数据如下:
Player Player_Rank Score_Game1 Score_Game2 Score_Game3 Score_Game1_r Score_Game2_r Score_Game3_r
Tom 1 87 84 92 87 84 92
John 2 91 84 87 91 84 87
Peter 3 81 83 83 81 83 83
Hank 4 85 72 57 . . .
Alfred 5 60 58 54 . . .
Mike 6 79 74 64 . . .
Joe 7 49 81 62 . . .
Marc 8 70 87 47 . . .
Sean 9 73 51 69 . . .
我想要的原因是我想计算每场比赛的AVG(得分)以及AVG仅适用于所有时间前3位的球员。谢谢。